第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

vue.js編寫移動端頁面,檢測旋轉(zhuǎn)屏幕,橫豎屏。

vue.js編寫移動端頁面,檢測旋轉(zhuǎn)屏幕,橫豎屏。

繁星coding 2019-03-07 14:13:04
初學(xué)vue,想要在檢測到旋轉(zhuǎn)屏幕后顯示遮罩層?,F(xiàn)在我的想法是在mounted時期添加監(jiān)聽屏幕旋轉(zhuǎn)事件,如果檢測到了,則修改data中的值isShowCover來改變v-show中的真假值,來達(dá)到顯示隱藏遮罩層的目的。但是mounted時期好像取不到data中的值。我是用alert來判斷取不取的到值的.this.isShowCover 是undefinedthis.showCover() alert都不提示了。this.$options.methods.showCover() alert也不提示了。所以想問的是想要監(jiān)聽到旋轉(zhuǎn)屏幕事件,這個事件應(yīng)該加在哪里?檢測到旋轉(zhuǎn)屏幕事件后,怎么才能把isShowCover的值改變來顯示隱藏遮罩層?data中的值大概是什么時候可以取到并且修改?提前感謝下回答的大佬。下面附主要代碼。<template><div v-show="isShowCover" style = "position:fixed;background:transparent;background:rgba(0,0,0,0.5);margin:auto;top:0;bottom:0;left:0;right:0">          <img src="../../pic/rotatePic.png" style="width:200px;height:200px;margin:auto;top:0;bottom:0;left:0;right:0"></div></template><script>export default {    data: () => ({      isShowCover: false    }),    mounted() {    window.addEventListener(      "onorientationchange" in window ? "orientationchange" : "resize",      function() {        if (window.orientation === 90 || window.orientation === -90) {            //想把下面的alert換成能夠控制v-show的代碼                      alert(            this.$options.methods.showCover() +              "橫屏可能導(dǎo)致頁面異常,建議豎屏操作!"          );          //alert("123");僅alert純文本可以正常運行        }        //window.location.reload();      },      false      );    },    methods:{        showCover() {          return "123";        },    }</script>
查看完整描述

1 回答

?
富國滬深

TA貢獻(xiàn)1790條經(jīng)驗 獲得超9個贊

listener 里的 function 的 this 不對吧, 指向的應(yīng)該不是 vue 的 this, 換成() => 應(yīng)該就好了.


<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() +

              "橫屏可能導(dǎo)致頁面異常,建議豎屏操作!"

          ); // 這里用 this 作用域就不對了.

          //alert("123");僅alert純文本可以正常運行

        }

        //window.location.reload();

      },

      false

      );

    },

    methods:{

        showCover() {

          return "123";

        },

    }

</script>


查看完整回答
反對 回復(fù) 2019-03-16
  • 1 回答
  • 0 關(guān)注
  • 3791 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號