dcloudio / uni-app

A cross-platform framework using Vue.js
https://uniapp.dcloud.io
Apache License 2.0
39.9k stars 3.62k forks source link

vue3 微信编译不支持v-bind #3330

Closed MackJac closed 2 years ago

MackJac commented 2 years ago

问题描述 vue3 使用了v-bind,h5端运行良好,微信端编译报错如下:

vite v2.7.13 building for development... [plugin:vite:vue] unknown directive{"type":7,"name":"bind","exp":{"type":4,"loc":{"source":"","start":{"line":1,"column":1,"offset":0},"end":{"line":1,"column":1,"offset":0}},"content":"b","isStatic":false,"constType":0},"modifiers":[],"loc":{"start":{"column":9,"line":7,"offset":181},"end":{"column":11,"line":10,"offset":252},"source":"v-bind=\"{\r\n title: '无敌',\r\n name: '防静电黄飞鸿'\r\n }\""}} at pages/index/index.vue:1:0

复现步骤 [复现问题的步骤]

  1. npm install
  2. npm run dev:h5 成功
  3. npm run dev:mp-weixin 失败

问题demo:https://gitee.com/mymjc/uniapp-vue3-demo.git

fxy060608 commented 2 years ago

小程序端暂不支持v-bind

MackJac commented 2 years ago

那什么时候能支持呢,有没有这个计划?

fxy060608 commented 2 years ago

那什么时候能支持呢,有没有这个计划?

自定义组件可以支持v-bind

MackJac commented 2 years ago

我demo里就是自定义组件,还是报错呢,麻烦看下

fxy060608 commented 2 years ago

我demo里就是自定义组件,还是报错呢,麻烦看下

我的意思是可以做到支持,但是还没支持,稍后发布一个cli版本支持

fxy060608 commented 2 years ago

已支持,cli更新至:3.0.0-alpha-3040220220310002 注意:你的代码里test组件没有声明具体的props

MackJac commented 2 years ago

其实我用v-bind就是为了隐性传参数,避免再封装已定义十几个参数的组件又要声明一次,我测试了下,你的更新还是要声明了才行,但是h5是不用的,直接拿到了

fxy060608 commented 2 years ago

其实我用v-bind就是为了隐性传参数,避免再封装已定义十几个参数的组件又要声明一次,我测试了下,你的更新还是要声明了才行,但是h5是不用的,直接拿到了

必须声明,可以把props的定义抽出来共享

MackJac commented 2 years ago

我用v-bind="$attrs"可以了,但是Uni官方组件不支持

fxy060608 commented 2 years ago

其实我用v-bind就是为了隐性传参数,避免再封装已定义十几个参数的组件又要声明一次,我测试了下,你的更新还是要声明了才行,但是h5是不用的,直接拿到了

cli更新至:3.0.0-alpha-3040220220310003 已支持未声明props的情况下使用v-bind

jdz321 commented 2 years ago

component上是支持了,element上还不支持呢 @fxy060608 uni-mp-compiler/transforms/transformElement

  if (!arg) {
      if (isVOn) {
          context.onError((0, errors_1.createMPCompilerError)(0 /* X_V_ON_NO_ARGUMENT */, loc));
      }
      if (isVBind && (!isComponent || isPluginComponent)) {
          context.onError((0, errors_1.createMPCompilerError)(2 /* X_V_BIND_NO_ARGUMENT */, loc));
      }
      continue;
  }
fxy060608 commented 2 years ago

component上是支持了,element上还不支持呢 @fxy060608 uni-mp-compiler/transforms/transformElement

  if (!arg) {
      if (isVOn) {
          context.onError((0, errors_1.createMPCompilerError)(0 /* X_V_ON_NO_ARGUMENT */, loc));
      }
      if (isVBind && (!isComponent || isPluginComponent)) {
          context.onError((0, errors_1.createMPCompilerError)(2 /* X_V_BIND_NO_ARGUMENT */, loc));
      }
      continue;
  }

注意看回复,只支持自定义组件使用

jdz321 commented 2 years ago

component上是支持了,element上还不支持呢 @fxy060608 uni-mp-compiler/transforms/transformElement

  if (!arg) {
      if (isVOn) {
          context.onError((0, errors_1.createMPCompilerError)(0 /* X_V_ON_NO_ARGUMENT */, loc));
      }
      if (isVBind && (!isComponent || isPluginComponent)) {
          context.onError((0, errors_1.createMPCompilerError)(2 /* X_V_BIND_NO_ARGUMENT */, loc));
      }
      continue;
  }

注意看回复,只支持自定义组件使用

咱知道啊,就是希望Element也支持v-bind,是feature request不是bug,您别恼火

fxy060608 commented 2 years ago

component上是支持了,element上还不支持呢 @fxy060608 uni-mp-compiler/transforms/transformElement

  if (!arg) {
      if (isVOn) {
          context.onError((0, errors_1.createMPCompilerError)(0 /* X_V_ON_NO_ARGUMENT */, loc));
      }
      if (isVBind && (!isComponent || isPluginComponent)) {
          context.onError((0, errors_1.createMPCompilerError)(2 /* X_V_BIND_NO_ARGUMENT */, loc));
      }
      continue;
  }

注意看回复,只支持自定义组件使用

咱知道啊,就是希望Element也支持v-bind,是feature request不是bug,您别恼火

由于目前底层实现的问题(静态编译转换+小程序底层不支持类似v-bind的用法),不大可能支持element的v-bind,所以才会在实现自定义组件的v-bind之后,就关闭了该issue。

sugar258596 commented 4 months ago

现在还是不支持啊,自定义指令h5 正常使用,都是编译到小程序就不行了

leemotive commented 2 months ago

现在还是不支持啊,自定义指令h5 正常使用,都是编译到小程序就不行了

我这也是不支持,在自定义组件上使用v-bind 可以,在内置组件上使用 v-bind 有问题。有没有谁解决过呢

aorange98 commented 1 month ago

他妈的还是不支持 草