目录加载页面自动触发函数实例页面加载时,触发某个函数的方法解决方法如下加载页面自动触发函数 实例 methods:{ onCreate:async function()
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修饰,不然就会获取不到数据。
需要在加载页面的时候调用生成验证码的click事件函数
利用Vue中的mounted
mounted:function(){
this.createcode();//需要触发的函数
}
//下面是createcode函数
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;
});
},
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: vue实现加载页面自动触发函数(及异步获取数据)
本文链接: https://www.lsjlt.com/news/153241.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0