Vuejs-if..else 语句中未达到第二个 axios.get [英] Vuejs- Second axios.get not reached in if..else statement
问题描述
所以我有这个 vue,它从另一个 vue 获取 id 和 user_type.我有两种用户类型:fr 和 en 都有自己的 get 请求来获取正确的数据.这就是我传递它们的方式:
So I have this vue where it gets id and user_type from another vue . I have two user types : fr and en both have their own get request to get the right data . this is how I passed them down :
const click = (record) => {
router.push({
name:'details' , params:{id:record.id,user_type:record.user_type},
})
}
现在在名为details"的新 vue 文件中,我执行以下操作:
Now in my file of my new vue named 'details' I do this :
let id =route.params.id
let user_type=route.params.user_type
onMounted(async () => {
if(user_type="fr")
{
await axios
.get('/lang/DetailFR/'+id)
.then((res) => {
dataSource.value = res.data
console.log( "here",dataSource.value )
})
.catch((err) => console.log(err))
}
else if (user_type="en") {
await axios
.get('/lang/DetailFEN/'+id)
.then((res) => {
dataSource.value = res.data
console.log( "where",dataSource.value )
})
.catch((err) => console.log(err))
}
})
所以当它是 user_type=fr 时它工作正常我在控制台中使用here"获取数据msg 但如果我的 user_type 是 =en 我在控制台中得到的是here";而不是哪里"并且没有明显的数据显示,所以if else"不工作,我不知道为什么.PS:如果我只使用 user_type=en 我会得到正确的工作请求和what"msg 显示所以问题出在 if..else 或其他东西上.有什么帮助吗?
SO when it's user_type=fr it works fine I get the data in console with the "here" msg but if my user_type is =en what I get in console is "here" and not "where" and no data desplayed obviously so the "if else " is not working and I don't know why. PS: if I only use user_type=en I get the right request to work and the "what" msg shown so problem is with the if..else or something. Any help please?
推荐答案
user_type===="fr"
而不是 user_type="fr"
这篇关于Vuejs-if..else 语句中未达到第二个 axios.get的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!