[英]Importing variable to vue file
I need import some variable to vue component file. 我需要导入一些变量以vue组件文件。 I am doing it this way:
我这样做是这样的:
require('imports-loader?myVar=>{test:12345}!./my-com.vue');
As result I get [Vue warn]: Error in render function: "ReferenceError: myVar is not defined"
结果,我收到
[Vue warn]: Error in render function: "ReferenceError: myVar is not defined"
I know about props
, but I want pass namely a variable. 我知道
props
,但是我想传递一个变量。
Here "my-com.vue": 这里是“ my-com.vue”:
<template>
<div>...</div>
</template>
<script>
console.log(myVar); // <--- here I get vue warn
export default {
props:['rows'],
...
}
</script>
Importing is from here: 从这里导入:
module.exports = function(params){
return function(resolve, reject){
resolve({
components:{
'my-com': require('imports-loader?myVar=>{test:12345}!./my-com.vue')
},
...
})
}
}
Where I am wrong? 我哪里错了?
How it possible to import a variable to vue component file? 如何将变量导入vue组件文件?
Thanks in advance. 提前致谢。
you can use an import
statement 您可以使用
import
语句
<script>
import { myVar } from './path_to_the_file'
console.log(myVar);
export default {
props:['rows'],
...
}
</script>
make sure you use the export statement in the other file to export myVar
like this: 确保使用另一个文件中的export语句来导出
myVar
如下所示:
export var myVar = 'my variable';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.