Aurelia中的Switch语句

如何在Aurelia中调用函数并将参数传递给switch语句?这是我的示例:

home.html

<template>
<input type="text" value.bind="FruitName">
<div class="Fruit">
<a href="http://www.example.com/${TypeOfFruit(FruitName)}" target="_blank"><a>
</template>

home.js

export class Home {

  TypeOfFruit(fruits) {
    text = ""
    switch (fruits) {
      case "Banana":
        text = "Banana is good!";
        break;
      case "Orange":
        text = "I am not a fan of orange.";
        break;
      case "Apple":
        text = "How you like them apples?";
        break;
      default:
        text = "I have never heard of that fruit...";
    }
    return this.text;
  }
}
ecason 回答:Aurelia中的Switch语句

您需要的是value-converter, 这些是特殊功能,可以在绑定时使用您想要的任何逻辑(包括switch)来转换数据。

本文链接:https://www.f2er.com/2827468.html

大家都在问