【发布时间】:2017-07-20 08:42:59
【问题描述】:
我需要将一些变量导入到 vue 组件文件中。我是这样做的:
require('imports-loader?myVar=>{test:12345}!./my-com.vue');
结果我得到[Vue warn]: Error in render function: "ReferenceError: myVar is not defined"
我知道props,但我想传递一个变量。
这里是“my-com.vue”:
<template>
<div>...</div>
</template>
<script>
console.log(myVar); // <--- here I get vue warn
export default {
props:['rows'],
...
}
</script>
从这里导入:
module.exports = function(params){
return function(resolve, reject){
resolve({
components:{
'my-com': require('imports-loader?myVar=>{test:12345}!./my-com.vue')
},
...
})
}
}
我哪里错了?
如何将变量导入 vue 组件文件?
提前致谢。
【问题讨论】:
-
你想从哪里导入这个变量?。它是否存在于另一个
.js文件中?
标签: javascript vue.js vue-component