<template>
<div>
<input type="text" v-model="article.text">{{ article.text }}</div>
<div> <input type="text" v-model="comments">{{ comments }}</div>
<div> <button @click="changeArticleText">点我</button></div>
<div> <button @click="addComment">加评论</button></div>
<div> <button @click="clearComments">清评论</button></div>
</template>
<script>
export default {
data() {
return {
article: {
text: 'Vue is awesome!'
},
comments: ['Indeed!', 'I agree']
}
},
created() {
this.$watch('article', () => {
console.log('Article changed!')
})
this.$watch('comments', () => {
console.log('Comments changed!')
})
},
methods: {
changeArticleText() {
this.article.text = 'Vue 3 is awesome'
},
addComment() {
this.comments.push('New comment')
},
changeWholeArticle() {
this.article = { text: 'Vue 3 is awesome' }
},
clearComments() {
this.comments = []
}
}
}
</script>
console.log('Comments changed!')
这段出来了
data() {
return {
article: {
text: 'Vue is awesome!'
},
comments: ['Indeed!', 'I agree']
这段应该如何引用?v-for吗?
|