Vue 使用自定義組件時報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#'

自己試做了一下vue的插件

參考element-ui:

寫了一個組件

import message from './packages/message/index.js';

const install = function (Vue, options) {
    if(install.installed ) return;
      //console.log(Vue)
    // 1. 添加全局方法或屬性
    Vue.prototype.myMessage= message;


    Vue.prototype.dtime=function(time){
        let d=Date.parse(time);
        let now =Date.parse(new Date()); 
        //console.log(now - d);
        let sec= parseInt((now- d)/1000);

        if(sec <60){
            return sec+'秒前';
        }else if(sec <3600){
            return parseInt(sec/60)+'分鍾前';
        }else if(sec <(24*3600)){
            return parseInt(sec/3600) +'小時前';
        }else if(sec <(24*3600*30)){
            return parseInt(sec/24/3600) + '天前';
        }else{
            return "一個月以前";
        }
        //return t[0]+t[1].substr(0,8);
    }



 }

module.exports = {
    install
}

結果就報

Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

后來網上查了之后說,這個是因為webpack 2中不允許混用import和module.exports,

解決辦法就是統一改成ES6的方式編寫即可.

export default {
    install,
};

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue報錯:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解決方法 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object 的解決方法 vue 項目啟動報錯:Cannot assign to read only property 'exports' of object '#' vue運行報錯error:Cannot assign to read only property 'exports' of object '#' 解決 Cannot assign to read only property 'exports' of object '#' 問題 Cannot assign to read only property 'exports' of object '#'
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM