創建自定義組件
1、新建 組件.vue 文件 2、組件文檔結構 <template name="組件名稱"> <view> ...... </view> </template> <script> export default { name: "組件名稱", //屬性 props: { 屬性名稱: { type: String,//屬性類型 value: "值" }, ...... }, //組件生命周期 created:function(e){
}, methods: { 函數名稱:function(obj){ }, }
}
</script>
<style>
組件樣式
</style>
使用組件
1、引用組件
import 組件名稱 from "../../components/組件名.vue";
2、注冊組件
export default{
components:{
組件名稱
},
}
3、在試圖模板中使用組件
<組件名稱 組件屬性="對應的值"></組件名稱>