methods: {
device: function () { //判断手机类型
const u = navigator.userAgent; //用户代理,声明了浏览器用于 HTTP 请求的用户代理头的值 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。
const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if (isAndroid)
return 'android';
if (isiOS)
return 'ios';
},
},
mounted: function mounted() {
var that = this;
this.$nextTick(function () {
if (this.device() === 'ios') {
$("input").each(function () { //只能遍历jquery对象 指的是dom对象及input
$(this).blur(function () { //当元素失去焦点时发生 blur 事件。
window.scroll(0, 0); //设置滚动条滚动到顶部
})
})
}
})
},
created: function created() {
var useragent = navigator.userAgent; //通过userAgent是否包含MicroMessenger来判断是否在微信内置浏览器打开网页
if (useragent.match(/MicroMessenger/i) != "MicroMessenger") {
return false;
}
},