vue3 Typescript基本使用

定义对象:

//设置范型
interface Istate {
  name: string,
  age: number,
  [key: string]: any;
}
const myName: Istate = reactive({
  name: '张三',
  age: 18,
  address: '北京',
  sex: '男'
})

ref



//DOM对象
const mydiv = ref()

//基本数据类型
const text =ref("你好")

props


emit

//父组件
 

const handleEvent=(value:string)=>{
    console.log(value)
}

//子组件
const emit = defineEmits<{ (e: 'event', value: string): void }>()
//自定义点击方法
const clickHandle = () => {
    emit("event", '123')
}

你可能感兴趣的:(typescript,javascript,前端)