从变量路径名导入组件

时间:2019-06-14 17:05:27

标签: vue.js electron

我需要将字符串连接起来,该字符串包含一个vue文件的路径,然后导入该文件。

我尝试了以下代码:

const electron = require('electron');
const fs = require('fs');
// let electron know which OS is used and get the right path, the path is different on each OS.
const userDataPath = (electron.app || electron.remote.app)
    .getPath('appData');

let import_path = userDataPath + '/Test.vue';

import test from import_path;

/src/renderer/router.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (15:17)

  13 | let import_path = userDataPath + '/Test.vue';
  14 | 
> 15 | import test from import_path;

如何导入vue文件?

0 个答案:

没有答案