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

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.

主站蜘蛛池模板: 澄迈县| 安陆市| 民勤县| 平和县| 南阳市| 镇雄县| 灵宝市| 文登市| 韶关市| 原阳县| 鲁甸县| 南木林县| 手游| 家居| 牙克石市| 酒泉市| 永仁县| 上饶县| 登封市| 花垣县| 宿松县| 揭西县| 石城县| 巴马| 永安市| 班玛县| 遂平县| 育儿| 临邑县| 定兴县| 嘉禾县| 永定县| 屯昌县| 永靖县| 霸州市| 景德镇市| 巴彦淖尔市| 同德县| 台中县| 望奎县| 得荣县|