官术网_书友最值得收藏!

Computed

Computed properties allow for multiple expressions to be passed, and these properties on the Vue instance require the use of class getters/setters. So, if we wanted to retrieve a reversed version of our name, we could simply pass the following:

@Component({
template: `
<div>
<input type="text" v-model="name" />
<button @click="sayHello(name)">Say Hello!</button>
<p>{{nameReversed}}</p>
</div>
`
})
export default class App extends Vue {
@Prop({ default: 'Paul Halliday' }) name: string;

// Computed values
get nameReversed() {
return this.name.split("").reverse().join("");
}

sayHello(name: string): void {
alert(`Hello ${name}`)
}
}

This would otherwise have been equivalent to:

export default {
computed: {
nameReversed() {
return this.name.split("").reverse().join("");
}
}
}

Other decorators can be used, such as @Watch, @Inject, @Model, and @Provide. Each decorator allows for a consistent implementation, and provides a similar API to the vanilla Vue instance. In the next section, we're going to look at how we can enhance the reactivity of our Vue applications with RxJS.

主站蜘蛛池模板: 东丰县| 沐川县| 无为县| 法库县| 永清县| 兰考县| 嘉鱼县| 武宣县| 舞钢市| 二连浩特市| 昌平区| 清苑县| 广南县| 长宁区| 青川县| 调兵山市| 蒙山县| 静海县| 景洪市| 江北区| 古蔺县| 黔东| 贺州市| 抚远县| 南华县| 界首市| 泗水县| 黄陵县| 扬中市| 仁寿县| 通城县| 东海县| 黄梅县| 门头沟区| 长汀县| 天峻县| 嘉善县| 麻城市| 崇阳县| 盐山县| 莎车县|