【发布时间】:2020-05-12 23:19:51
【问题描述】:
我是 VUE 新手,我尝试修改 disabled 值取决于 userAgent 显示或隐藏 paymentMethod:
data() {
return {
paymentMothods: [
{ name: 'Visa checkout', img: 'visa.png', disabled: false, height: '19', class: 'v-button' },
{ name: 'PayPal', img: 'paypal.png', disabled: false, height: '18.9', class: '' },
{ name: 'PhonePE', img: 'phonepe.png', disabled: true, height: '18.9', class: 'phonepe' },
]
}
},
如果 userAgent 是 phonepe-webview 我尝试更改值:
methods: {
phopepeMatch: function () {
let userAgent = navigator.userAgent
let phonepeMatch = userAgent.match("phonepe-webview")
if (phonepeMatch === "phonepe-webview"){
this.paymentMothods[2].disabled = false
return true
}
else {
return false
}
}
},
但这并没有显示付款方式:(
【问题讨论】:
-
匹配区分大小写 - 另外,
phopepeMatch方法是如何/在哪里调用的?还有一件事,match 返回 null 或数组 - 所以你想要if (phonepeMatch && phonepeMatch[0] === "phonepe-webview") -
将
console.info(phonepeMatch)放在if语句之前的一行中。显示什么? -
剧透警报:
.match()返回一个数组,而不是字符串。您的函数将始终返回 false:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
标签: javascript vue.js user-agent