爱上了你的
爱上了你的
  • 发布:2019-08-17 13:50
  • 更新:2020-11-15 23:58
  • 阅读:12793

uni-app里怎么调用引入的微信小程序自定义组件里的方法

分类:uni-app

uni-app里引入了微信自定义组件,然后想调用自定义组件里的方法,微信小程序里是用selectComponent获取组件然后就可以调用了,但uni-app里好像没有selectComponent这个方法,看文档也没找到类似的,要怎么改啊

2019-08-17 13:50 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com - 呵呵哒

<cusTab ref="myTab"></cusTab>  

this.$refs.myTab.selectTab(0);
  • BruceLeung

    这个才是正解,用的是vuejs的ref特性

    2019-10-12 11:12

  • 2lii

    正解

    2019-11-06 20:04

  • 3***@qq.com

    使用自定义模式编译 uni-app 这样写没有用的

    2019-11-13 14:49

DCloud_UNI_GSQ

DCloud_UNI_GSQ

this.$scope.selectComponent

  • 爱上了你的 (作者)

    大佬,我按照你这么写了,但还是报Cannot read property 'selectComponent' of undefined啊

    2019-08-17 17:18

DCloud_UNI_GSQ

DCloud_UNI_GSQ

你是使用的非自定义组件编译模式吗?是的话先用this.$mp.page.selectComponent

uni小白一枚

uni小白一枚

我也遇到了这个问题,把代码从微信小程序搬到uni 不知道怎么修改uni里面获取自定义组件的方法,用了this.$scope.selectComponent 也是提示Cannot read property 'selectComponent' of undefined

自用仓库

自用仓库

具体怎么用啊,有没有例子,简单的使用自定义组件里面的方法

1***@qq.com

1***@qq.com

this.$scope.selectComponent('#id')是这样用的吗?
null是什么原因?

拾荒

拾荒 - 可以不说话吗?

解决了吗?怎么弄到?能不能分享一下?

zhangdaren

zhangdaren - 小程序转uniapp工具:https://ext.dcloud.net.cn/plugin?id=2656

大佬解决了吗?

zhangdaren

zhangdaren - 小程序转uniapp工具:https://ext.dcloud.net.cn/plugin?id=2656

var pages = getCurrentPages();  
var ctx = pages[pages.length - 1];  
var pageCtx = ctx.selectComponent(selector);  
//原始小程序代码:pageCtx.setData({show:true}); 在小程序上报错  
pageCtx.$vm.setData({show:true}); 

作用:取到某个组件的实例对象,并调用它的方法。

以上代码在微信/百度/字节跳动小程序上测试通过, (qq小程序未装未测试,支付宝小程序页面直接报错,没到那一步)

再看了一下,

this.$scope.selectComponent("#id"); //可以取到实例
DCloud_heavensoft

DCloud_heavensoft

小程序组件可以用。但其实没必要用。性能不如uni-app 的vue组件好,无法自动差量diff数据,还得手动setData,写的多别扭,干干净净使用vue语法多好。

s***@qq.com

s***@qq.com

请问这个实例你取到了吧,可以指点我一下吗?wx:samsmallpawpaw

该问题目前已经被锁定, 无法添加新回复