vue.js - Vue 可以读取属性
问题描述
在我的项目中,我使用 axios 和状态管理。我有模型的存储和单独文件。在组件中然后安装我运行
this.$store.dispatch('getComputer2', this.$route.params.id);
并使用 v-model 进行绑定。如果我从另一个页面打开页面按下按钮
<router-link tag="button" :to="{ name: 'computerEdit', params: { id: row.item.id } }" class="btn btn-danger">Edit</router-link>
没有错误。但是,如果按 F5 或在控制台中打开页面直接链接,我会看到错误: [Vue 警告]:渲染错误:“TypeError:无法读取 null 的属性‘名称’”
在组件中我使用计算属性:
computed: {
computer: {
get() {
return this.$store.state.computer.computer;
},
set() {
this.$store.dispatch("addComputer", this.computer);
}
}
有什么区别?
附加代码:
接收数据的动作
const state = {
computer: null
};
getComputer2 ({commit}, id) {
axios.get('/actives/GetComputer/' + id)
.then(res => {
let computer = res.data;
console.log(computer)
commit('SET_COMPUTER', computer);
})
而这个观点:
<b-form-group id="input-group-2" label="PC Name:" label-for="input-2">
<b-form-input
id="input-2"
v-model="computer.name"
required
placeholder="Enter name"
></b-form-input>
</b-form-group>
解决方案
推荐阅读
- scenekit - SwiftUI + Scenekit + Combine + GeometryReader ==> 可滚动的 3D 模型列表 + 通过滚动列表旋转 3D 模型
- ffmpeg - ffmpeg如何使用AMD硬件加速编码器?
- database - 有谁知道保存参数和过程名称(Oracle)的示例结构表?
- java - 何时使用 firebase 功能以及何时使用 firestore 客户端功能?
- javascript - 什么都不等?使用空等待来分解大型同步函数
- python - 我如何打印在 if 语句中执行的值或方程
- flutter - 移动到另一个页面时如何隐藏按钮导航栏?
- html - 在 Google Cloud Storage 存储桶中上传时如何自动设置 Content-Type 文件?
- node.js - 如何在 Graphql Schema 中表示 mongoose 的 objectID 数组
- api - Twitter 流 API 返回提及推文