鍍金池/ 問答/HTML5  PHP  HTML/ 使用es6寫頁面,編譯成es5,引入之后提示exports is not def

使用es6寫頁面,編譯成es5,引入之后提示exports is not defined

es6的寫法
import './library/jquery-1.11.3.min.js';
import './library/vue-2.2.6.min.js';
export default {

el: '.login-box',
data() {
    return {
        email: '',
        password: ''
    };
},
methods: {
    login() {
        const self = this;
        if (!self.email || !self.password) {
            alert('請?zhí)顚懲暾卿浶畔?);
            return;
        }
        $.ajax({
            type: "POST",
            url: "/index.php/backend/login_validate",
            data: {
                name: self.email,
                password: self.password
            },
            dataType: "json",
            success: function (data) {
                if (data.error_code) {
                    alert(data.msg);
                } else {
                    window.location.href = "/index.php/backend/index";
                }
            }
        });
    }
}

}

編譯之后es5的文件

'use strict';

Object.defineProperty(exports, "__esModule", {

value: true

});

require('./library/jquery-1.11.3.min.js');

require('./library/vue-2.2.6.min.js');

exports.default = {

el: '.login-box',
data: function data() {
    return {
        email: '',
        password: ''
    };
},

methods: {
    login: function login() {
        var self = this;
        if (!self.email || !self.password) {
            alert('請?zhí)顚懲暾卿浶畔?);
            return;
        }
        $.ajax({
            type: "POST",
            url: "/index.php/backend/login_validate",
            data: {
                name: self.email,
                password: self.password
            },
            dataType: "json",
            success: function success(data) {
                if (data.error_code) {
                    alert(data.msg);
                } else {
                    window.location.href = "/index.php/backend/index";
                }
            }
        });
    }
}

};
//# sourceMappingURL=login.js.map

引入頁面居然報(bào)錯(cuò)

clipboard.png

回答
編輯回答
兮顏

babelimport/export轉(zhuǎn)換為CommonJS規(guī)范的語法,只能通過webpack等基于Node的工具來打包,瀏覽器原生不支持CommonJS

2017年12月3日 15:52
編輯回答
誮惜顏

dablwow80 正解

2017年6月16日 22:16
編輯回答
話寡

這樣試試?

    import $ from './library/jquery-1.11.3.min.js';
    import Vue from './library/vue-2.2.6.min.js';
2017年1月10日 17:16