NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.34k stars 4.77k forks source link

引用vant weapp中时间选择器组件,formatter和filter属性传参无法接收,无法正常使用 #10028

Open lubo-fline opened 3 years ago

lubo-fline commented 3 years ago

相关平台

微信小程序

复现仓库

https://github.com/lubo-fline/meeting 小程序基础库: 8.0.3 使用框架: Vue 2

复现步骤

在页面中引入

<van-datetime-picker
                type="time"
                :value="dateTimePicker.time"
                :min-hour=" 8 "
                :max-hour='19'
                :filter=" filter "
                @confirm='timeConfirm'
                @cancel='isShowPicker=""'
            />

在methods中或者data中添加变量

filter(type, options){
            console.log(options)
            if (type === 'minute') {
                return options.filter((option) => option % 30 === 0);
            }
            return options;
        },

会发现console没有执行,并且组件中时间没有过滤。 在vant weapp组件源码中create里获取filter属性为undefined

期望结果

期望可以告知如何传函数类属性,并且可以正常传

实际结果

vant组件接收不到方法类属性,不知道是写法不对还是有问题。

环境信息

$ taro info
👽 Taro v3.2.10

  Taro CLI 3.2.10 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 14.17.3 - D:\Program Files\nodejs\node.EXE
      npm: 7.17.0 - D:\Program Files\nodejs\npm.CMD

补充信息

在日期组件中添加 :formatter='formatter' 在data或者methods中添加对应属性值

formatter(type, value) {
                if (type === 'year') {
                    return `${value}年`;
                } 
                if (type === 'month') {
                    return `${value}月`;
                }
                return value;
            },

运行后页面报错

VM728 WAService.js:2 Unhandled promise rejection TypeError: formatter is not a function
    at index.js? [sm]:115
    at Array.map (<anonymous>)
    at index.js? [sm]:115
    at Array.map (<anonymous>)
    at vt.updateColumns (index.js? [sm]:114)
    at index.js? [sm]:311
    at VM728 WAService.js:2
    at r (VM728 WAService.js:2)(env: Windows,mp,1.05.2107221; lib: 2.17.0)

在日期组件中同样接收不到传过来的方法

tu6ge commented 3 years ago

这个问题建议在 vant 项目中发起,由 vant 和 taro 一起排查一下这个问题,或在如果你有兴趣,可以阅读源码,自己贡献代码解决

lubo-fline commented 3 years ago

这个问题建议在 vant 项目中发起,由 vant 和 taro 一起排查一下这个问题,或在如果你有兴趣,可以阅读源码,自己贡献代码解决

好哒,我自己也研究下~

lubo-fline commented 3 years ago

https://github.com/youzan/vant-weapp/issues/4176 https://github.com/youzan/vant-weapp/issues/4403 vant这边也有提问题

maopixin commented 2 years ago

请问有解决吗,我在上面的一个issues中看到taro解决了vue3无法传递function的问题,但是我是用vue2依然是有问题的

lubo-fline commented 2 years ago

这是来自QQ邮箱的自动回复邮件。您好,我已经收到你的邮件,谢谢。。。