ts引入组件

ts引入组件

1.首先在 global.d.ts 文件中加上一段代码
主要目的是让ts文件识别vue组件,不然报错

// 让ts文件认识vue模板
declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent
  export default component
}

2.在组件文件中引入 defineComponent

import { onBeforeMount, ref, defineComponent,reactive } from "vue";
export default defineComponent({
  name:"Head", //一般可以不写name防止因为name冲突导致的死循环
  setup() {
    const msg = ref("Hello world GanYunFei");
    const test:Object = reactive({a:1}); //reactive的作用,让数据变成可监测的,reactive主要用来定义响应式的复合数据类型,他的作用就是不会改变对象本身,但是会改变对象里面属性的值
    const tests:Object = ref(2) //ref的作用是,让数据变成可以监测的,ref主要是针对基本数据类型
    //生命周期都写在这里
    onBeforeMount(() => {});
    return {
      msg,
      test,
      tests
    };
  },
  components: {
  },
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值