VUE3-TS定义reactive数据类型
Typescript
·
reactive
<script setup lang="ts">
import { reactive } from 'vue'
interface useInfoModel {
name:string;
id:string|number;
actaver?: any;
}
const userInfo = ref<userInfoModel>()
let msg = reactive<number[]>([0, 4, 6])
const btn1 = () => {
msg[0] = 12 // 由于 设置当前 msg为num类型的数组 若是 ‘12’会提示报错
console.log('msg', msg, msg[0])
}
</script>
// 或者
type headType = {
title:string,
icon:string
}
let msg = reactive<headType>({title:"字符串",icon:"字符串icon"})
const btn1 = () => {
msg.title = 5555 //报错
}
//默认值
interface tabBar {
title: string;
id: string | number;
render: boolean;
}
interface Props {
tabbarPage: tabBar[];
}
const props = withDefaults(defineProps<Props>(), {
tabbarPage: ()=>[
{
title: "标题",
id: 1,
render: false,
}
],
});
更多推荐
所有评论(0)