当前位置:网站首页>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>
边栏推荐
- vscode离线安装插件方法
- 刷题-洛谷-P1319 压缩技术
- seata源码解析:seata server各种消息处理流程
- awk 统计差值记录
- A complete cross-compilation environment records the shell scripts generated by peta
- 刷题-洛谷-P1179 数字统计
- Order of lds links
- Client Side Cache 和 Server Side Cache 的区别
- 长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
- win10 uwp modify picture quality compress picture
猜你喜欢
随机推荐
How to manually download and install SAP Fiori tools - Extension Pack for Visual Studio Code
uwp ScrollViewer content out of panel when set the long width
A complete cross-compilation environment records the shell scripts generated by peta
使用 Allatori 进行 Jar 包混淆
JS手写JSON.stringify() (面试)
How to promote the implementation of rural revitalization
AWS SES 的监控和告警
node 的运行命令
【CAS:2306109-91-9 |胺-PEG4-脱硫生物素】价格
JSD-2204-酷莎商城(管理员模块)-密码加密-Day10
Nuxt.js的优缺点和注意事项
密码学系列之:PEM和PKCS7,PKCS8,PKCS12
新式茶饮,卷完水果还能卷什么?
常用正则表达式[通俗易懂]
电脑一键重装系统后连不上远程了?教你设置的方法
简易数据缓存层的建立
ASP.NET商贸进销存管理系统源码(带数据库文档)源码免费分享
"WAIC 2022 · hackers marathon" two ants wealth competition invited you to fight!
【Web漏洞探索】跨站脚本漏洞
visual studio 与 visual studio code








