Uni-App - 自定義組件 - 自定義組件創建及使用


創建自定義組件

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、在試圖模板中使用組件
<組件名稱 組件屬性="對應的值"></組件名稱>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM