【问题标题】:Import file dynamically in vue js在 vue js 中动态导入文件
【发布时间】:2017-03-31 15:18:34
【问题描述】:

下面的代码适合我

var Index = require('./theme/dir1/index.vue');

但我想这样使用它,

var path = './theme/'+variable+'/index.vue';
var Index = require(path);

这对我不起作用,有什么办法可以解决这个问题。,

【问题讨论】:

  • @moáois 变量在路径之前定义
  • @moáois btw 我使用 webpack 作为依赖管理器
  • 这不是进口,这是必需的。名字不好。

标签: javascript reactjs meteor vue.js vuejs2


【解决方案1】:

试试这个,它应该可以工作:

var Index = require(`./theme/${variable}/index.vue`);

【讨论】:

  • 但不需要大括号
  • 内括号还是外括号?你能展示一下你在用什么吗?
  • var Index = require(`./theme/${variable}/index.vue`);
猜你喜欢
  • 2022-10-19
  • 2020-01-24
  • 2019-04-23
  • 2019-08-03
  • 2019-06-25
  • 2021-09-21
  • 1970-01-01
  • 2019-05-12
  • 2020-06-18
相关资源
最近更新 更多