鍍金池/ 問(wèn)答/HTML/ vue和iview,用babel-polyfill了,還是報(bào)錯(cuò),下面是代碼

vue和iview,用babel-polyfill了,還是報(bào)錯(cuò),下面是代碼

main.js入口文件

import App from "./App";
import router from "./router";
import Vuex from "vuex";
import store from "@/store";
import "iview/dist/styles/iview.css";
import "./assets/my-theme/index.less";
import "@/assets/common.css";
import { Switch, Message } from "iview";
import vueI18n from "vue-i18n";
import lang from "./i18n/index";
import infiniteScroll from "vue-infinite-scroll";
import "babel-polyfill";
import DefauleImg from '@/assets/images/lesson_default.png';
Vue.use(infiniteScroll);

Vue.use(vueI18n);

// import MsgModal from '@/components/common/MsgModal';
Vue.config.productionTip = false;
Vue.component("i-switch", Switch);
Vue.prototype.$Message = Message;
Vue.prototype.$Local = window.localStorage;

Vue.prototype._imageError = function(){
  e.target.src = DefauleImg;
};
Vue.filter("formatclass", function(value) {
  switch (value) {
    case 1:
      return "1對(duì)1";
      break;
    case 2:
      return "小班課";
      break;
    case 3:
      return "直播課";
      break;
    default:
      return "";
  }
});
// Vue.component('msg-modal',MsgModal);
if (
  localStorage.getItem("userinfo") == null ||
  localStorage.getItem("userinfo") == "" ||
  localStorage.getItem("key") == null ||
  localStorage.getItem("key") == ""
) {
  localStorage.removeItem('userinfo');
  localStorage.removeItem('key');
  //ie兼容
  if (window["context"] == undefined) {
    if (!window.location.origin) {
      location.origin = window.location.protocol + "http://" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
    }
    window["context"] = location.origin + "/V6.0";
  }
  window.location.href = location.origin + "/admin/login/login.html";
}

const i18n = new vueI18n({
  locale: "en",
  messages: lang
});

/* eslint-disable no-new */
new Vue({
  el: "#app",
  i18n,
  router,
  store,
  components: { App },
  template: "<App />"
});

webpack
 entry: {
    app: ["babel-polyfill", "./src/main.js"]
  },

.babelrc
{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": ["transform-vue-jsx", "transform-runtime"]
}

clipboard.png

clipboard.png

clipboard.png

回答
編輯回答
孤客

babel-polyfill一般都是放在最上面的.. 因?yàn)榭赡苣阌玫牟寮蛘吣承┛蚣苡昧诵绿匦缘腁PI,放在最開(kāi)頭能保證先進(jìn)行polyfill

2017年12月30日 01:21
編輯回答
孤影

clipboard.png

目前為了解決按需加載后 iview babel 問(wèn)題,只能手動(dòng)定義 babel 文件路徑了

{
    test   : /\.js$/,
    use    : 'babel-loader',
    include: [resolve('node_modules/iview/src'), resolve('node_modules/webpack-dev-server/client')]
}
2017年8月8日 23:02
編輯回答
失心人

建議把這個(gè)import "babel-polyfill";寫(xiě)到最前面

2017年9月1日 14:51