1 回答
TA贡献1790条经验 获得超9个赞
listener 里的 function 的 this 不对吧, 指向的应该不是 vue 的 this, 换成() => 应该就好了.
<script>
export default {
data: () => ({
isShowCover: false
}),
mounted() {
let self = this; // 这里
window.addEventListener(
"onorientationchange" in window ? "orientationchange" : "resize",
function() {
if (window.orientation === 90 || window.orientation === -90) {
//想把下面的alert换成能够控制v-show的代码
alert(
self.$options.methods.showCover() +
"横屏可能导致页面异常,建议竖屏操作!"
); // 这里用 this 作用域就不对了.
//alert("123");仅alert纯文本可以正常运行
}
//window.location.reload();
},
false
);
},
methods:{
showCover() {
return "123";
},
}
</script>
添加回答
举报
