Vue.js 中将数据赋值给 data 属性的 prompt 的方法
在 Vue.js 方法中使用 this 来访问 data 中的 prompt 属性,然后将 json 赋值给 prompt 即可。代码如下:
search: function(e) {
var json = e.value;
this.prompt = json; // 将 json 赋值给 prompt
if (json == '') {
uni.showToast({
title: '请输入内容',
mask: true,
icon: 'success',
duration: 1500
});
} else {
this.submitData();
}
},
解释:
this指向当前 Vue 实例,可以通过this访问data中的属性。this.prompt = json;将json的值赋值给data中的prompt属性。
示例:
export default {
data() {
return {
prompt: '',
};
},
methods: {
search: function(e) {
var json = e.value;
this.prompt = json;
// ...
},
},
};
在 search 方法中,当用户输入内容时,json 将被赋值给 this.prompt,从而更新 prompt 的值。
原文地址: https://www.cveoy.top/t/topic/fYCs 著作权归作者所有。请勿转载和采集!