dcloudio / uni-app

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

HbuilderX2.3.0/2.3.1不支持这种写法吗?编译直接报错 #798

Closed lizhenyuls closed 5 years ago

lizhenyuls commented 5 years ago

问题描述 [问题描述:尽可能简洁清晰地把问题描述清楚]

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

[或者可以直接贴源代码]

<template>
  <view class="content">
    <view class="text-area" @click="test().then(() =>{ cLog() })">
      <text class="title">{{ title }}</text>
    </view>
  </view>
</template>

<script>
    export default {
        data() {
            return {
                title: 'Hello'
            }
        },
        methods: {
            test() {
                return Promise.resolve()
            },
            cLog() {
                console.log('test')
            }
        }
    }
</script>

预期结果 [使用简洁清晰的语言描述你希望生效的预期结果]

实际结果 【编译报错】 09:43:14.304 TypeError: Property value expected type of string but got null 09:43:14.304 at Object.validate (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\definitions\utils.js:164:13) 09:43:14.311 at validateField (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\validators\validate.js:22:9) 09:43:14.311 at validate (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\validators\validate.js:16:3) 09:43:14.319 at builder (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\builders\builder.js:46:27) 09:43:14.328 at Object.StringLiteral (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\builders\generated\index.js:337:31) 09:43:14.337 at parseEventByCallExpression (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:175:30) 09:43:14.338 at exprStatements.forEach.exprStatement (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:282:15) 09:43:14.351 at Array.forEach (<anonymous>) 09:43:14.362 at valuePath.forEach.funcPath (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:281:28) 09:43:14.373 at Array.forEach (<anonymous>) 09:43:14.374 at parseEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:235:15) 09:43:14.383 at _processEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:368:9) 09:43:14.393 at processEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:427:5) 09:43:14.394 at processes.forEach.process (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:34:5) 09:43:14.410 at Array.forEach (<anonymous>) 09:43:14.420 at traverseData (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:33:13) 09:43:14.430 TypeError: Property value expected type of string but got null 09:43:14.439 at Object.validate (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\definitions\utils.js:164:13) 09:43:14.440 at validateField (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\validators\validate.js:22:9) 09:43:14.450 at validate (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\validators\validate.js:16:3) 09:43:14.451 at builder (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\builders\builder.js:46:27) 09:43:14.460 at Object.StringLiteral (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\builders\generated\index.js:337:31) 09:43:14.461 at parseEventByCallExpression (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:175:30) 09:43:14.473 at exprStatements.forEach.exprStatement (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:282:15) 09:43:14.473 at Array.forEach (<anonymous>) 09:43:14.481 at valuePath.forEach.funcPath (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:281:28) 09:43:14.488 at Array.forEach (<anonymous>) 09:43:14.498 at parseEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:235:15) 09:43:14.505 at _processEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:368:9) 09:43:14.505 at processEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:427:5) 09:43:14.515 at processes.forEach.process (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:34:5) 09:43:14.516 at Array.forEach (<anonymous>) 09:43:14.525 at traverseData (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:33:13) 09:43:14.526 TypeError: Property value expected type of string but got null 09:43:14.534 at Object.validate (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\definitions\utils.js:164:13) 09:43:14.535 at validateField (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\validators\validate.js:22:9) 09:43:14.544 at validate (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\validators\validate.js:16:3) 09:43:14.544 at builder (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\builders\builder.js:46:27) 09:43:14.554 at Object.StringLiteral (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\builders\generated\index.js:337:31) 09:43:14.555 at parseEventByCallExpression (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:175:30) 09:43:14.564 at exprStatements.forEach.exprStatement (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:282:15) 09:43:14.565 at Array.forEach (<anonymous>) 09:43:14.574 at valuePath.forEach.funcPath (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:281:28) 09:43:14.581 at Array.forEach (<anonymous>) 09:43:14.582 at parseEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:235:15) 09:43:14.590 at _processEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:368:9) 09:43:14.591 at processEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:427:5) 09:43:14.599 at processes.forEach.process (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:34:5) 09:43:14.599 at Array.forEach (<anonymous>) 09:43:14.606 at traverseData (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:33:13) 09:43:14.616 TypeError: Property value expected type of string but got null 09:43:14.616 at Object.validate (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\definitions\utils.js:164:13) 09:43:14.623 at validateField (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\validators\validate.js:22:9) 09:43:14.624 at validate (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\validators\validate.js:16:3) 09:43:14.634 at builder (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\builders\builder.js:46:27) 09:43:14.634 at Object.StringLiteral (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\node_modules\@babel\types\lib\builders\generated\index.js:337:31) 09:43:14.642 at parseEventByCallExpression (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:175:30) 09:43:14.651 at exprStatements.forEach.exprStatement (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:282:15) 09:43:14.651 at Array.forEach (<anonymous>) 09:43:14.651 at valuePath.forEach.funcPath (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:281:28) 09:43:14.666 at Array.forEach (<anonymous>) 09:43:14.666 at parseEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:235:15) 09:43:14.666 at _processEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:368:9) 09:43:14.682 at processEvent (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\event.js:427:5) 09:43:14.682 at processes.forEach.process (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:34:5) 09:43:14.682 at Array.forEach (<anonymous>) 09:43:14.682 at traverseData (D:\Program Files\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:33:13)

系统信息:

补充信息 [可选] [根据你的分析,出现这个问题的原因可能在哪里?]

fxy060608 commented 5 years ago

2.3.0以后默认启用自定义组件模式,该模式性能更高,但可能不支持部分复杂事件写法,建议如果复杂的话,重新封装一个事件方法

lizhenyuls commented 5 years ago

2.2.2版本启用启用自定义组件模式编译都没问题

lizhenyuls commented 5 years ago
<template>
  <view class="content">
    <view class="text-area" @click="true ? test().then(() =>{ cLog() }) : cLog">
      <text class="title">{{ title }}</text>
    </view>
  </view>
</template>

<script>
    export default {
        data() {
            return {
                title: 'Hello'
            }
        },
        methods: {
            test() {
                return Promise.resolve()
            },
            cLog() {
                console.log('test')
            }
        }
    }
</script>

这样又能编译