uniapp 小程序不支持的语法(启动报错)
一些常用在vue中的语法,在uniapp(小程序)中不支持
·
uniapp 小程序 启动报错 (不支持的语法)
错误堆栈没有自己写的文件 ,估计是template编译时错误
注
- Q$:出现的问题
- A$:问题原因
- 建议检索的正则:
方案\d*
Q1: TypeError: Property value expected type of string but got null
TypeError: Property value expected type of string but got null
at Object.validate (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\types\lib\definitions\utils.js:160:13)
at validateField (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\types\lib\validators\validate.js:24:9)
at validate (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\types\lib\validators\validate.js:17:3)
at builder (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\types\lib\builders\builder.js:38:27)
at Object.StringLiteral (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\types\lib\builders\generated\index.js:350:31)
at D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\class.js:58:11
at Array.forEach (<anonymous>)
at processClassObjectExpression (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\class.js:53:17)
at processClass (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\class.js:84:11)
at D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:34:5
at Array.forEach (<anonymous>)
at traverseData (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:33:13)
at Object.CallExpression (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\visitor.js:186:58)
at NodePath._call (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\path\context.js:55:20)
at NodePath.call (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\path\context.js:42:17)
at NodePath.visit (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\path\context.js:90:31)
Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):
Error: Compile failed at common/components/Button/index.vue
at compile (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\index.js:140:13)
at actuallyCompile (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\@vue\component-compiler-utils\dist\compileTemplate.js:70:96)
at compileTemplate (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\@vue\component-compiler-utils\dist\compileTemplate.js:31:16)
at Object.<anonymous> (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\vue-loader\lib\loaders\templateLoader.js:46:20)
A1: template中不支持对象属性模板字符串
<view
:class="{
plain,disabled,
[`theme-${theme}`]:theme,
[`prefix-${prefix}`]:prefix,
[`suffix-${prefix}`]:suffix,
}"
>
方案:将class改为了一个computed::class="computedClass"
Q2 TypeError: Cannot read property ‘name’ of undefined
TypeError: Cannot read property 'name' of undefined
at D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\style.js:86:41
at Array.forEach (<anonymous>)
at processStyleObjectExpression (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\style.js:79:17)
at processStyle (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\style.js:128:11)
at D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:34:5
at Array.forEach (<anonymous>)
at traverseData (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\data\index.js:33:13)
at Object.CallExpression (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\script\traverse\visitor.js:186:58)
at NodePath._call (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\path\context.js:55:20)
at NodePath.call (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\path\context.js:42:17)
at NodePath.visit (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\path\context.js:90:31)
at TraversalContext.visitQueue (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\context.js:112:16)
at TraversalContext.visitSingle (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\context.js:84:19)
at TraversalContext.visit (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\context.js:140:19)
at Function.traverse.node (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\index.js:84:17)
at NodePath.visit (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@babel\traverse\lib\path\context.js:97:18)
Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):
Error: Compile failed at common/components/_Project/Code/CodeInput.vue
at compile (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\uni-template-compiler\lib\index.js:140:13)
at actuallyCompile (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\@vue\component-compiler-utils\dist\compileTemplate.js:70:96)
at compileTemplate (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\@vue\component-compiler-utils\dist\compileTemplate.js:31:16)
at Object.<anonymous> (D:\pro\HBuilderX\plugins\uniapp-cli\node_modules\@dcloudio\vue-cli-plugin-uni\packages\vue-loader\lib\loaders\templateLoader.js:46:20)
A2: template中不支持对象展开运算
<view v-for="num in maxlength" :key="num" class="item" :class="{'item-active':num<=valueLength+1}"
:style="{
width,height,marginRight:num===maxlength?0:split,
...((num<=valueLength+1)?activeItemStyle:itemStyle),
}"
>...</view>
方案:在组件外部使用类名改变样式(不支持函数传参,不支持展开对象,不会了orz)
更多推荐
已为社区贡献1条内容
所有评论(0)