vendor.js:22967 ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(LoginModule)[

项目场景:

vendor.js:22967 ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(LoginModule)[NzMessageService -> NzMessageService -> NzMessageService -> NzMessageService]:

问题描述:

引用antZorro的全局提示出错,

原因分析:

没有注入NzMessageService

解决方案:

在module.ts文件里添加provider:[NzMessageService]就可以了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
出现这个错误的原因是`localStorage`在某些环境中不可用,导致无法读取`getItem`属性。 为了解决这个问题,你可以在访问`localStorage`之前进行检查。如果`localStorage`不可用,你可以使用一个备选方案来存储和获取数据,比如使用`sessionStorage`或者使用一个普通的JavaScript对象来模拟本地存储。 下面是修改后的代码示例,使用一个普通的JavaScript对象来模拟本地存储: ```html <template> <uni-forms ref="mineForm" :rules="mineRules" :modelValue="mineFormData"> <uni-forms-item label="姓名" :required="true" name="name"> <uni-easyinput v-model="mineFormData.name" placeholder="请输入姓名"></uni-easyinput> </uni-forms-item> </uni-forms> <button type="primary" size="mini" @click="save('mineForm')">保存</button> </template> <script> export default { data() { return { mineFormData: { name: this.getLocalStorageData('name') || '', // 从本地存储中获取已保存的姓名 }, mineRules: { name: { rules: [ { required: true, errorMessage: '姓名不能为空', }, ], }, }, }; }, methods: { getLocalStorageData(key) { if (typeof localStorage !== 'undefined') { return localStorage.getItem(key); } else { return this.storage[key]; } }, setLocalStorageData(key, value) { if (typeof localStorage !== 'undefined') { localStorage.setItem(key, value); } else { this.storage[key] = value; } }, save(ref) { this.$refs[ref].validate().then(res => { console.log('success', res); this.setLocalStorageData('name', this.mineFormData.name); // 将姓名保存在本地存储中 uni.showToast({ title: '保存成功', }); }).catch(err => { console.log('err', err); }); }, }, created() { this.storage = {}; // 创建一个对象来模拟本地存储 }, }; </script> ``` 通过在`getLocalStorageData`和`setLocalStorageData`方法中检查`localStorage`的可用性,并使用一个普通的JavaScript对象来模拟本地存储,这样可以避免在不支持`localStorage`的环境中出现错误。同时,你可以在`created()`钩子函数中创建一个空对象来模拟本地存储。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值