Javascript VUE:未捕获类型错误:无法读取属性';长度';未定义的
我正在学习vue教程。下面是在文本区域上实现字符限制的函数Javascript VUE:未捕获类型错误:无法读取属性';长度';未定义的,javascript,vue.js,Javascript,Vue.js,我正在学习vue教程。下面是在文本区域上实现字符限制的函数 <form action="" class="create-twoot" @submit.prevent="createnewTwoot"> <label for="new-twoot">New Twoot</label> <p>{{char_limit}}/180</p> <
<form action="" class="create-twoot" @submit.prevent="createnewTwoot">
<label for="new-twoot">New Twoot</label>
<p>{{char_limit}}/180</p>
<textarea name="" id="new-twoot" cols="30" rows="4" v-model="newTwootcontent"></textarea>
<br/>
<label for="newTwootType">Twoot Type</label>
<select name="TwootType" id="newTwootType" v-model="twootType">
<option :value="option.name" v-for="(option,index) in twootTypes" :key="index">
{{option.value}}
</option>
</select>
<br/>
<button>Tweet</button>
</form>
其他一切正常,但此字符限制给出了以下错误
(我没有发布数据、方法等,因为它们工作正常)
有人能告诉我代码有什么问题吗定义数据段中的变量
export default {
name: 'Userprofile',
data() {
return {
newTwootcontent: '',
twootType: 'instant',
};
}
computed:{
char_limit(){
return this.newTwootcontent.length;
},
fullname(){
return `${this.users.fname} ${this.users.lname}`;
}
},
}
首先查看基础知识、数据和方法:@lawrencerone我已经添加了方法和数据,它正在运行查找,请让我知道我是否应该按原样发布代码,否则您在vue实例上定义了数据中应该包含的内容,这是错误的,因此error@LawrenceCherone根据Amaarrockz的回答,我在数据内部定义了NewWootContent,它解决了这个问题,感谢它在几分钟内允许接受,只需一个澄清,所有属性都需要在数据内部定义?请确认是的,所有变量都应该在数据中定义,只有这样才能使用“this”运算符访问它们。也不要混淆计算和方法和数据变量,因为它们也可以使用“this”操作符访问
Cannot read property 'length' of undefined
at Proxy.char_limit (Userprofile.vue?5045:102)
export default {
name: 'Userprofile',
data() {
return {
newTwootcontent: '',
twootType: 'instant',
};
}
computed:{
char_limit(){
return this.newTwootcontent.length;
},
fullname(){
return `${this.users.fname} ${this.users.lname}`;
}
},
}