简单的组件化开发
组件就是 xx.vue
<!-- 第二部分 -->
<!-- 以后在这个对象中写咱们之前学的data,methods,watch,computed,生命周期钩子 -->
<script>
export default {
data() {
return {
name: 'szw'
}
},
props:["msg"]
}
</script>
<!-- 第一部分 -->
<!-- 组件必须套在一个标签内部,之前用反引号写的html内容 -->
<template>
<h1>{{msg}}</h1>
<div><span @click="name='szw2'">{{ name }}</span></div>
</template>
<!-- 第三部分:这里面写样式 -->
<style>
span{
color: red;
}
</style>
在根组件App.vue 中使用这个组件
<script>
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
import HelloWorld from './components/HelloWorld.vue'
export default{
data() {
return {
msg:'父'
}
},
// 注册组件
components:{
HelloWorld,
}
}
</script>
<template>
<div>
<h1>组件化开发</h1>
<HelloWorld :msg="msg" />
</div>
</template>
<style scoped>
</style>
本文作者:Sherwin
本文链接:https://www.cnblogs.com/sherwin1995/p/16850998.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步