vue的两种风格--选项式API

<script>
export default {
data() {
return {
count: 0
}
},
methods: {
increment() {
this.count++
}
},
mounted() {
console.log(`The initial count is ${this.count}.`)
}
}
</script>


<template>
<button @click="increment">Count is: {{ count }}</button>
</template>

 

使用选项式 API,我们可以用包含多个选项的对象来描述组件的逻辑,例如 data、methods 和 mounted。

选项所定义的属性都会暴露在函数内部的 this 上,它会指向当前的组件实例。

选项式API就是VUE2的写法

posted @ 2023-06-27 00:18  叁三彡  阅读(65)  评论(0编辑  收藏  举报