当前位置: 首页> 健康> 知识 > Vue3 项目结构

Vue3 项目结构

时间:2025/7/9 16:53:23来源:https://blog.csdn.net/qq_53374893/article/details/141470664 浏览次数:0次

1.main.ts

2.简单写一个src下的结构

App.vue 根组件 

<template><div class="app"><!-- html --><h1>你好啊!</h1></div>
</template><script lang="ts">
//js 或 tsexport default {name:'App',//组件名
};</script><style scoped>
/* css */
.app{background-color: #ddd;box-shadow: 0 0 10px;border-radius: 10px;padding: 20px;
}
</style>

 main.ts

//引入 createApp用于创建应用
import {createApp} from 'vue';
//引入 App 根组件
import App from './App.vue';createApp(App).mount('#app');

3.回顾vue2

<template><div class="person"><h2>姓名:{{ name }}</h2><h2>年龄:{{ age }}</h2><button @click="changeName">修改名字</button><button @click="changeAge">修改年龄</button><button @click="showTel">查看联系方式</button></div>
</template><script lang="ts">
export default {name: "Person",data() {return {name: "张三",age: 18,tel: "123456",};},methods: {changeAge() {this.age = 13;},changeName() {this.name = "zhang-san";},showTel() {alert(this.tel);},},
};
</script><style scoped>
.person {background-color: skyblue;box-shadow: 0 0 10px;border-radius: 10px;padding: 20px;
}
button{margin:  0 5px;
}
</style>

证明Vue3 能向下兼容 vue2 的语法

关键字:Vue3 项目结构

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: