vue實(shí)現(xiàn)加載頁(yè)面自動(dòng)觸發(fā)函數(shù)(及異步獲取數(shù)據(jù))
更新時(shí)間:2022年07月02日 08:56:05 作者:不說(shuō)廢話斯基
這篇文章主要介紹了vue實(shí)現(xiàn)加載頁(yè)面自動(dòng)觸發(fā)函數(shù)(及異步獲取數(shù)據(jù)),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
加載頁(yè)面自動(dòng)觸發(fā)函數(shù)
實(shí)例
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 () { //自動(dòng)觸發(fā)寫入的函數(shù)
this.onCreate();
}
觸發(fā)模板為
methods: {
? ? ? ? ? demo() {
? ? ? ? ??
? ? ? ? ? }
? ? ? },
?mounted: function () {
? alert('頁(yè)面一加載,就會(huì)彈出此窗口')
?}要在fuction() 前面用async修飾、外部調(diào)用前面用await修飾,不然就會(huì)獲取不到數(shù)據(jù)。
頁(yè)面加載時(shí),觸發(fā)某個(gè)函數(shù)的方法

需要在加載頁(yè)面的時(shí)候調(diào)用生成驗(yàn)證碼的click事件函數(shù)
解決方法如下
利用Vue中的mounted
mounted:function(){
this.createcode();//需要觸發(fā)的函數(shù)
}
//下面是createcode函數(shù)
createcode(){
var self = this;
axios.post("/verifycode",{name:this.name,id:this.id}).then(function(res){
//console.log(res);
var url= JSON.parse(res.data.code64);
//console.log(url)
self.urlIMg = url.data.base64Code;
});
},以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue實(shí)現(xiàn)雙向綁定的原理以及響應(yīng)式數(shù)據(jù)的方法
這篇文章主要介紹了Vue實(shí)現(xiàn)雙向綁定的原理以及響應(yīng)式數(shù)據(jù)的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
vue函數(shù)input輸入值請(qǐng)求時(shí)延遲1.5秒請(qǐng)求問(wèn)題
這篇文章主要介紹了vue函數(shù)input輸入值請(qǐng)求時(shí)延遲1.5秒請(qǐng)求問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04

