vue3setup()格式 以及 清除文本框内容 vue3
格式
<input
type="text"
placeholder="what needs to be done?"
@keyup.enter="addValue(inputValue)"
v-model="inputValue"
/>
setup() {
// 声明变量 变量都需要声明 ref里面放这个变量的类型
const arr = ref([]);
const inputValue = ref("");
// 定义方法 ------------------------- 开始
const addValue = (content) => {
const val = {
// content: content, 两个相同的 键:值 ;可以直接写一个
content,
checked: false,
id: arr.value.length + 1,
};
arr.value.push(val);
// arr.value.content = "";
inputValue.value = "";
这个可以清除文本框的值,最后的时候需要返回
};
// const addValue =() => {} 函数尽量写成这种形式
// 定义方法 ------------------------- 结束
return {
arr,
inputValue,
//页面上有的东西基本上都需要返回,返回只有一个对象
addValue,
};

浙公网安备 33010602011771号