数组循环改变一个对象名称
if (res.data?.length) {
categoryList.value = res.data.map((v: Recordable) => ({ ...v, text: v.name }));
}
可以判断登录按钮禁止点击
const submitted = computed(() => {
return unref(mobile) && unref(smsCode) && unref(pwd) && unref(pwd2);
});
vue3 hooks
import { reactive, toRefs, unref } from 'vue';
import { Toast } from 'vant';
export function useSmsCode() {
const state = reactive({
wenzi:"你好",
captchaShow: false,
});
function onSmsBtnClicked() {
Toast('请输入手机号信息');
}
function dosomething(){
console.log("nihao")
}
return {
...toRefs(state),
onSmsBtnClicked,
dosomething,
};
}
api代码
import {doRequestAction} from '../utils/request'
export const MAINLINK = 'https://sy-food.net/'
// export const MAINLINK = 'http://172.16.92.54/'
// 声明获取主题首页接口地址并导出
export const MerchantOrder= (params, basicinfo)=>{
return doRequestAction({
url: MAINLINK + 'ncppos-api/business/sales-order',
method:'GET',
data: {
beginTime:params.beginTime,
endTime:params.endTime,
page:params.page,
size:params.limit,
supplierSubjectId:basicinfo.account.subjectId,
},
})
}
export const addNewCustomer = (params) =>{
return doRequestAction({
url: MAINLINK + 'ncppos-api/business/customer',
method:'POST',
data:params,
loadIng:true,
})
}
// import Taro from '@tarojs/taro'
import { getLocalUserInfo } from './userInfo'
const getRequestHeader = () => {
let token = getLocalUserInfo() ? getLocalUserInfo().tokenValue : "";
return token ? {
"content-type": 'application/json',
token: token
} : {
"content-type": 'application/x-www-form-urlencoded',
token: ""
}
}
// 请求传入reqData参数 返回promise对象 因为全局请求我每次返回的类型都是不一样的,所以我直接any
export const doRequestAction = (reqData) => {
// 将不存在的参数字段使用默认值进行替换
let req = { ...reqData }
return new Promise((resolve, reject) => {
//检测是否开启loading层
if (req.loadIng) {
wx.showLoading({
title: "数据加载中",
icon: "none"
})
}
wx.request({
url: req.url, //引入我的接口是特殊声明的,所以我就不检测http/https了
method: req.method,
data: req.data,
header: getRequestHeader(),
success(res) {
wx.hideLoading()
const code = res.statusCode
if(res.data.code==-1){
wx.showToast({
icon: 'none',
title: res.data.message,
})
}
if (code == 200) { // 请求成功
resolve(res.data);
} else if (code == 401) {
wx.showToast({
icon: 'none',
title: 'Token失效,请重新登录',
})
wx.redirectTo({
url: '../login/login',
})
reject('运行时错误,请稍后再试')
} else {
reject('运行时错误,请稍后再试'); // 其他异常
}
},
fail(err) {
wx.showToast({
icon: 'none',
title: err.errMsg,
})
wx.hideLoading()
// 请求失败
reject(err)
}
})
})
}
网友评论