Vue.js 在vue中,当更改其他变量时,不能更改一个变量的值

Vue.js 在vue中,当更改其他变量时,不能更改一个变量的值,vue.js,Vue.js,当我输入'count'的值时,我想立即更改'countcolor'的值。 我不理解这个值的绑定,或者这个组件需要引入吗? 怎么办 <div id="app-13"> give a count to know the color (0,1 or anything)<br> <input type="text" name="" v-model="cou

当我输入'count'的值时,我想立即更改'countcolor'的值。 我不理解这个值的绑定,或者这个组件需要引入吗? 怎么办

<div id="app-13"> 
            give a count to know the color (0,1 or anything)<br>
            <input type="text" name="" v-model="count" v-on:keyup.enter="cometh"><br> 
            <p>when the count is {{ count }}<br>
              color is <span>{{ countcolor }}</span>
            </p>
          </div>

这可以使用computed属性实现,如下所示

var app13 = new Vue({
  el: '#app-13',
  data: {
    count: 0,
  },
  computed:{
        countcolor() {       
            if(this.count === 0){
                return 'green'
            }else if(this.count === 1){
                return 'red'
            }else{
                return 'blue'
            }
        }
    }
})
然后你可以用

<div id="app-13"> 
            give a count to know the color (0,1 or anything)<br>
            <input type="text" name="" v-model="count"><br> 
            <p>when the count is {{ count }}<br>
              color is <span>{{ countcolor }}</span>
            </p>
          </div>

计数以了解颜色(0,1或任何颜色)

当计数为{{count}}
颜色是{{countcolor}}


==
比较两个值,
=
分配一个值。请参阅感谢您的帮助,但“如果其他”部分不起作用。此外,“countcolor”仅更改一次。请尝试将数据定义为functiondata(){return{count:0,}}得到相同的结果。请确保已从data()部分删除countcolor变量
<div id="app-13"> 
            give a count to know the color (0,1 or anything)<br>
            <input type="text" name="" v-model="count"><br> 
            <p>when the count is {{ count }}<br>
              color is <span>{{ countcolor }}</span>
            </p>
          </div>