当前位置:网站首页>ts集成和使用
ts集成和使用
2022-08-04 20:04:00 【大象与小蚂蚁的生活】
1、集成
进入到项目,执行下面的命令
vue add typescript
这里选择n,生成的组件就会和文档给的一样;y则组件是class类型
上面的程序运行完,typescript也就集成好啦!
2、使用

<template>
<div class="red">
{
{
name}}
<home/>
</div>
</template>
<script lang="ts">
import {
defineComponents,toRefs,reactive} from "vue"
import home from "./components/home.vue";
// data数据的接口
interface User {
name: string;
age: number;
get(): string;
}
export default defineComponent({
name:"App",
components:{
},
setup(){
// ref只能用第二种写法
// 实现接口的第一种方法 属性可增不可减
// let data: User = reactive({
// name: "张三",
// age: 12,
// get() {
// return this.name;
// },
// set(){}
// });
// 实现接口的第二种方法 属性不可增减
// let data = reactive<User>({
// name: "张三",
// age: 12,
// get() {
// return this.name;
// },
// });
// 实现接口的第三种方法 属性可增不可减
let data = reactive({
name: "张三",
age: 12,
get() {
return this.name;
},
set() {
},
}) as User;
return {
...toRefs(data),
};
}
})
</script>
<style lang="scss">
</style>
边栏推荐
猜你喜欢
随机推荐
【有奖征文】秋招特训,打造你的专属产品体验
hash和history路由的区别
电脑一键重装系统后连不上远程了?教你设置的方法
Use "green computing" technology to promote sustainable development of computing power
【Web漏洞探索】跨站脚本漏洞
C#将对象转换为Dictionary字典集合
Ant Group's time series database CeresDB is officially open source
Initialization process of SAP UI5
win10 uwp 修改图片质量压缩图片
使用百度EasyDL实现森林火灾预警识别
A complete cross-compilation environment records the shell scripts generated by peta
取证程序分类
C#弹出询问对话框
SAP UI5 ensures that the control id is globally unique implementation method
Force KouTi (5), the longest text string back
vscode离线安装插件方法
ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators
C#的Dictionary字典集合按照key键进行升序和降序排列
June To -.-- -..- -
MySQL字段类型








