当前位置:网站首页>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>
边栏推荐
猜你喜欢

二叉树是否对称

刷题-洛谷-P1304 哥德巴赫猜想

linkboy 5.0 正式发布,新增语音识别、图像识别

Qt Designer生成的图形可以自适应窗口的大小变化

电脑一键重装系统内存完整性无法打开怎么办

Chrome安装zotero connector 插件

电脑一键重装系统后连不上远程了?教你设置的方法

如何推动乡村振兴的落地

C#移动OA办公系统源码(基于微信企业号)

How to carry out AI business diagnosis and quickly identify growth points for cost reduction and efficiency improvement?
随机推荐
如何进行AI业务诊断,快速识别降本提效增长点?
jMeter Thread group 对应的 constant timer
C#移动OA办公系统源码(基于微信企业号)
How to use the Chrome DevTools performance tab
Desthiobiotin衍生物Desthiobiotin-PEG4-Amine/Alkyne/Azide/DBCO
How to monitor code cyclomatic complexity by refactoring indicators
如何找到某个 ABAP structure 某字段的源头来自哪个数据库表
MYSQL gets the table name and table comment of the database
带你了解数据分布式存储原理
二叉树的前序遍历
web 应用开发最佳实践之一:避免大型、复杂的布局和布局抖动
Seata source code analysis: various message processing processes of seata server
WIN10系统如何开启终端
v-model的使用
SAP 电商云 Accelerator 和 Spartacus UI 的工作机制差异
Client Side Cache 和 Server Side Cache 的区别
lds链接的 顺序问题
getBoundingClientRect
vscode离线安装插件方法
zynq records