vue在script中加入let报错
问题描述
在组件的script块中顶部定义let变量会报错,换成var没问题,let在方法中定义没问题,其他组件let定义也一样报同样的错误.求各位大大这个是出什么问题了,查资料也没查到,以前也没碰到过这样的问题.非常感谢
问题出现的环境背景及自己尝试过哪些方法
更换vue-loader版本无效
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
<script>
import Item from './item.vue'
import Tabs from './tabs.vue'
let id=1;
export default{
data(){
return{
todo:{
id:0,
content:'this is todo',
completed:false
},
filter:'all'
}
},
components:{
Item,
Tabs
},
methods:{
addTodo:function(){
let a=1;
//id=1;
}
}
}
</script>
你期待的结果是什么?实际看到的错误信息又是什么?
ERROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./src/todo/todo.vue
Module build failed: TypeError: Cannot read property 'bindings' of null
at Scope.moveBindingTo (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\scope\index.js:867:13)
at BlockScoping.updateScopeInfo (C:\Users\Sercl\Desktop\todox\node_modules\babel-plugin-transform-es2015-block-scoping\lib\index.js:364:17)
at BlockScoping.run (C:\Users\Sercl\Desktop\todox\node_modules\babel-plugin-transform-es2015-block-scoping\lib\index.js:330:12)
at PluginPass.BlockStatementSwitchStatementProgram (C:\Users\Sercl\Desktop\todox\node_modules\babel-plugin-transform-es2015-block-scoping\lib\index.js:70:24)
at newFn (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\visitors.js:193:21)
at NodePath._call (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\path\context.js:53:20)
at NodePath.call (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\path\context.js:40:17)
at NodePath.visit (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\path\context.js:88:12)
at TraversalContext.visitQueue (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\context.js:118:16)
at TraversalContext.visitSingle (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\context.js:90:19)
at TraversalContext.visit (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\context.js:146:19)
at Function.traverse.node (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\index.js:94:17)
at traverse (C:\Users\Sercl\Desktop\todox\node_modules\@babel\traverse\lib\index.js:76:12)
at transformFile (C:\Users\Sercl\Desktop\todox\node_modules\@babel\core\lib\transformation\index.js:88:29)
at runSync (C:\Users\Sercl\Desktop\todox\node_modules\@babel\core\lib\transformation\index.js:45:3)
at runAsync (C:\Users\Sercl\Desktop\todox\node_modules\@babel\core\lib\transformation\index.js:35:14)
@ ./src/todo/todo.vue 8:0-114 9:0-127
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./src/app.vue
@ ./src/app.vue
@ ./src/index.js
@ multi (webpack)-dev-server/client?http://0.0.0.0:8080 webpack/hot/dev-server ./src/index.js
Child html-webpack-plugin for "index.html":
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
package.json也没有,.babelrc也没有,只能期望:你使用了babel7,但是babel插件用的是babel-preset-latest,在这种情况下,请升级babel插件到:
@babel/preset-env