<script lang="ts" setup>
//设置一个初始化对象值
class formInit {
title = '',
sub = [],
img = ''
};
//定义对象的类型
interface FormItem {
title : string,
sub : string[],//数组 ['a','b']
img : string
};
const form = reactive<FormItem >(new formInit());
//执行操作,给form赋值
const swiperChange = () => {
form.title = '你好';
};
//初始化form
const reset = () => {
Object.assign(form, new formInit());
};
</script>
初学vue3与ts:reactive定义一个对象,重置到初始值
于 2024-07-03 17:39:31 首次发布