mpvue icon indicating copy to clipboard operation
mpvue copied to clipboard

mpvue无法使用selectComponent

Open kalooboy opened this issue 6 years ago • 8 comments

[问题简单描述]

问题复现步骤:

showDialog() {
      console.log(this);
      let dialogComponent = this.selectComponent(".wxc-dialog");
      dialogComponent && dialogComponent.show();
    },

在调用该方法时会报以下错误: image

期望的表现: 希望能给出一个使用的办法

kalooboy avatar Jun 06 '18 15:06 kalooboy

// 不能再created 里面调用 this.$mp.page.selectComponent('#xxx')

shaonialife avatar Jun 19 '18 04:06 shaonialife

@shaonialife this.$mp.page.selectComponent is not a function; 在onLoad里面调用也会提示这个错误,page对象里面没有这个方法 控制台里面输出page如下 2018-06-29 11 25 59

Jeesoong avatar Jun 29 '18 15:06 Jeesoong

@shaonialife created 是vue什么生命周期,不是小程序的,此时调用小程序实例肯定不对吧

jcto avatar Oct 28 '18 10:10 jcto

不论生命周期, 我在页面渲染好了也报错。 旧一点的版本mpvue 还可以使用selectComponent,最新版就不可以了。 这样使用一些第三方UI库会有影响。 求解决方案。

kevinlvhsl avatar Nov 19 '18 06:11 kevinlvhsl

不论生命周期, 我在页面渲染好了也报错。 旧一点的版本mpvue 还可以使用selectComponent,最新版就不可以了。 这样使用一些第三方UI库会有影响。 求解决方案。

新版的mpvue-cli脚手架中, 需要将main.js里面的config 改成main.json中去。

export default {
  config: {
    navigationBarTitleText: '登录',
    usingComponents: {
      'i-button': '/static/iView/button/index',
      'i-toast': '/static/iView/toast/index'
    }
  }
}

-> main.json

{
    "navigationBarTitleText": "登录",
    "usingComponents": {
        "i-button": "/static/iView/button/index",
        "i-toast": "/static/iView/toast/index"
    }
}

kevinlvhsl avatar Nov 19 '18 07:11 kevinlvhsl

不论生命周期, 我在页面渲染好了也报错。 旧一点的版本mpvue 还可以使用selectComponent,最新版就不可以了。 这样使用一些第三方UI库会有影响。 求解决方案。

不要放在 created 里,要放在 mounted 里。

iduma avatar Feb 26 '19 13:02 iduma

this.$root.$mp.page.selectComponent(.xxxx)

zavven avatar Apr 15 '19 14:04 zavven

和楼主2的没有什么区别 打印出来之后 会发现mpvue重写地page里面没有selectComponent方法

styjs avatar Sep 05 '20 06:09 styjs