vue加载页面自动触发函数(以及异步获取数据)--前端
实例:methods:{onCreate:async function(){const router = useRouter()const route = useRoute()const { id = '', f = 1 } = route.queryconsole.log("======="+id)const res = await reqGetOrderNumByClientId({clien
·
实例:
methods:{
onCreate:async function() {
const router = useRouter()
const route = useRoute()
const { id = '', f = 1 } = route.query
console.log("======="+id)
const res = await reqGetOrderNumByClientId({
clientId: id
})
console.log("-------------------"+res+res.msg)
if (res.code === 200) {
await router.push({
path: '/app/create',
query: {
id: id,
f: f
}
})
} else {
Dialog.alert({
title: '提示',
message: res.msg,
showCancelButton: false,
confirmButtonText: '确定'
})
}
}
},
mounted:function () { //自动触发写入的函数
this.onCreate();
}
触发模板为
methods: {
demo() {
}
},
mounted: function () {
alert('页面一加载,就会弹出此窗口')
}
要在fuction() 前面用async修饰、外部调用前面用await修饰,不然就会获取不到数据。
更多推荐
已为社区贡献1条内容
所有评论(0)