同一个页面需要通过判断来引入不同的文件时,发现 import 写在 if 中这种写法会导致加载不到文件,产生报错;
const platform= localStorage.getItem("platform");
if (platform === "pc") {
import { pc} from "@/store/modules/pc";
} else {
import { mobile } from "@/store/modules/mobile";
}
改用 require 方式引入即可
const platform= localStorage.getItem("platform");
let model = null;
if (system === "pc") {
model = require("@/store/modules/pc");
} else {
model = require("@/store/modules/mobile");
}
标签:es6,platform,mobile,modules,pc,WebPack,import,store
From: https://www.cnblogs.com/echohye/p/17142988.html