uniapp中使用selectComponent
普通的组件引用无法用selectComponent获取组件实例。
·
selectComponent:selectComponent('.class') // 返回组件的实例
selectComponent获取的是在globalStyle或是pages每个页面中注册的组件实例
1:"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8",
"usingComponents": {
"wxml-to-canvas": "/wxcomponents/wxml-to-canvas/index",
"content": "/pages/selectComponentApi/components/content/index"
}
},
2:"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "canvas",
"usingComponents": {
"wxml-to-canvas": "/wxcomponents/wxml-to-canvas/index"
}
}
},
],
页面中获取组件实例
// html
<wxml-to-canvas
class="widget"
id="widget"
:width="canvasWidth"
:height="canvasHeight"
/>
// js
onLoad() {
this.init()
},
methods: {
async init() {
setTimeout(() => {
this.widget = this.selectComponent(".widget") // 需要延迟
}, 1000)
},
},
普通的组件引用无法用selectComponent获取组件实例
更多推荐
已为社区贡献8条内容
所有评论(0)