网页学习体会

  • 首页
  • 个人博客
您的位置: 首页  >  IT文章  >  Vue 使用自定义组件时报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#'

Vue 使用自定义组件时报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#'
分类: IT文章 • 2023-11-04 08:53:35

自己试做了一下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,
};

相关推荐

  • Vue 使用自定义组件时报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#'
  • vue-cli3 打包时使用‘babel-loader’遇到Cannot assign to read only property ‘exports’ of object '#'问题的解决方法。 原文链接:http://www.pianshen.com/article/9677274805/
  • 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-cli 配合webpack4 报错 Cannot assign to read only property 'exports' of object '#' 解决方法
  • vue-cli3 打包时使用‘babel-loader’遇到Cannot assign to read only property ‘exports’ of object '#'问题的解决方法。
  • SPOJ SUBST1 后缀数组
  • POJ 3261 后缀数组
    • 网站免责声明 网站地图 最新文章 用户隐私 版权申明
    本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

    Copyright © 2018-2021   Powered By 网页学习体会    备案号:   粤ICP备20002247号