uni-app項目運行到小程序端,不會應用自定義組件,在uni-app升級到1.8版本後,會在小程序頁面的json文件中顯示自定義組件。
具體的配置步驟如下:
開發者可在manifest.json的源碼視圖裏配置, manifest.json
-> mp-weixin
-> usingComponents
切換編譯模式,如下:
// manifest.json
{
// ...
/* 小程序特有相關 */
"mp-weixin": {
"usingComponents":true //是否啓用`自定義組件模式`,爲true表示新的`自定義組件模式`,否則啓用老的`template模板模式`
}
}
這個時候,我們重新運行項目,編譯到小程序,我們則可以看到,小程序項目已經應用了自定義組件模式。首頁index.vue組件對應的小程序頁面配置如下:
{
"usingComponents": {
"index-list": "/components/index/index-list",
"swiper-tab-head": "/components/index/swiper-tab-head",
"load-more": "/components/common/load-more",
"no-thing": "/components/common/no-thing"
}
}
此時,已經是應用自定義組件模式了。
另外,在小程序端,使用自定義子組件引入的時候,此時點擊事件已經失效,問題的關鍵是修改了props中傳入對象的屬性,問題的解決方法是:重新定義要修改的屬性。代碼如下:
data() {
return {
isguanzhu: this.item.isguanzhu,
infonum: this.item.infonum
}
},
methods: {
// 關注
guanzhu() {
this.isguanzhu = true;
uni.showToast({
title: '關注成功',
});
},
}
邏輯分析:
修改item.isguanzhu屬性,這個時候要重新點擊一個新的變量isguanzu:this.item.isguanzu纔可以運行正常。