首先真机测试是这个问题:
TypeError: Cannot read property 'state' of undefined at D:/%E5%89%8D%E7%AB%AF%E9%A1%B9%E7%9B%AE/youqing_App/node_modules/@dcloudio/vue-cli-plugin-uni/packages/mpvue/index.js:638
表示state找不到,所以看了官方的demo,发现跟我的这个差不多,只是没有用这个namespace命名空间,这个是问题代码;
// vuex
import { createNamespacedHelpers } from "vuex"; // 取对应的模块
const { mapState, mapMutations } = createNamespacedHelpers("index");
// api
import {
userReverse,
getViewAllDay,
getYesNowTime,
getDeskNumber
} from "@/api/index";
export default {
components: {
commonHeader,
commonCustomer,
styleHead
},
onShow() {},
computed: {
...mapState([
"mealId",
"deviceContext",
"deviceTotal",
"choiseCutomer",
"confirm_type",
"money",
"pay_type",
"recive_num",
"contract_num",
"contract_image",
"undertake_type",
"undertake_time",
"undertake_id"
])
vuex代码是这样写的;
store->index.js
/**
index首页下的存储仓库
*/
export default {
namespaced: true,
state: {
// 销售选择客户的信息(id,名称,电话等)
choiseCutomer: {},
// 选择菜单的ID
mealId: 1,
// 选择菜单的备注
mealText: "",
// 设备的json字符串,设备id:设备数量
deviceContext: "",
// 设备的总额
deviceTotal: "",
undertake_id: "", // 如果合作方式为自营必填项
// 承办方式
undertake_type: 0,
undertake_time: "", // 自带/自营 入场时间必填,
// 以下为确认方式
confirm_type: "",
money: "",
pay_type: "",
recive_num: "", // 收款码(确认方式为现金必填)
contract_num: "", // 合同编码(确认方式为合同必填)
contract_image: "", // 合同字符串(确认方式为合同必填)
// 没有看错,没有担保人的选项
},
mutations: {
// 清空所有
deleteAll(state) {
state.mealId = 1;
state.mealText = "";
state.deviceContext = "";
state.deviceTotal = "";
state.undertake_id = "";
state.undertake_type = "";
state.undertake_time = "";
state.confirm_type = "";
state.money = "";
state.pay_type = "";
state.recive_num = "";
state.contract_num = "";
state.contract_image = "";
},
// 保存选择客户信息
saveCustomer(state, info) {
state.choiseCutomer.id = info.id;
state.choiseCutomer.name = info.name;
state.choiseCutomer.tel = info.tel;
},
// 确认方式保存
saveSuretype(state, info) {
state.money = info.money;
state.pay_type = info.pay_type;
state.recive_num = info.recive_num;
state.contract_image = info.contract_image;
state.contract_num = info.contract_num;
state.confirm_type = info.confirm_type;
},
// 承办方式保存
saveUnder(state, info) {
state.undertake_id = info.undertake_id;
state.undertake_type = info.undertake_type;
state.undertake_time = info.undertake_time;
},
// 把设备明细和设备总额保存进去
saveDevice(state, info) {
state.deviceContext = info.deviceContext;
state.deviceTotal = info.deviceTotal;
},
// 保存菜单把ID保存进去
saveMeal(state, info) {
state.mealId = info.mealId;
state.mealText = info.mealText;
}
},
actions: {
saveMeal(context, mealId) {
context.commit("saveMeal", mealId);
}
}
}
求官方人员复现代码,看看编译会不会出现问题;