做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

怎樣使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 19:42:48
文檔

怎樣使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單

怎樣使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單:這次給大家?guī)?lái)怎樣使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單,使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來(lái)看一下。這是個(gè)大多數(shù)網(wǎng)站很常見(jiàn)的功能,點(diǎn)擊頁(yè)面右上角頭像顯示一個(gè)懸浮菜單,點(diǎn)擊頁(yè)面其他位置或再次點(diǎn)擊頭
推薦度:
導(dǎo)讀怎樣使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單:這次給大家?guī)?lái)怎樣使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單,使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來(lái)看一下。這是個(gè)大多數(shù)網(wǎng)站很常見(jiàn)的功能,點(diǎn)擊頁(yè)面右上角頭像顯示一個(gè)懸浮菜單,點(diǎn)擊頁(yè)面其他位置或再次點(diǎn)擊頭

意思是:避免修改prop值,因?yàn)楦附M件一旦re-render,這個(gè)值就會(huì)被覆蓋;

另外,盡管在這個(gè)按鈕上實(shí)現(xiàn)了顯示狀態(tài)的切換,但是點(diǎn)擊其他區(qū)域的時(shí)候,并不會(huì)隱藏它,原因是:子組件prop值的變化并沒(méi)有影響到父組件,因此showCancel的值一直保持初始值沒(méi)有變化,而只有在這個(gè)值被更新時(shí)才會(huì)觸發(fā)子組件中相關(guān)值的更新。

——好吧,那么老老實(shí)實(shí)的用一個(gè)計(jì)算屬性接收showCancel值,這樣實(shí)現(xiàn)點(diǎn)擊子組件控制系統(tǒng)菜單的狀態(tài)切換;

獲得了計(jì)算屬性ifShowCancel,組件相應(yīng)的變成了v-show="ifShowCancel",我試圖在綁定事件里通過(guò)this.ifShowCancel=!this.ifShowCancel切換菜單狀態(tài),報(bào)錯(cuò),得到報(bào)錯(cuò)信息:Computed property "ifShowCancel" was assigned to but it has no setter;

明白了,要以直接賦值的形式改變計(jì)算屬性ifShowCancel的值,需要一個(gè)setter函數(shù),但是setter函數(shù)中無(wú)法修改prop值,因此在getter中也就無(wú)法通過(guò)return this.showCancel來(lái)更新這個(gè)計(jì)算屬性,所以這個(gè)方法貌似也行不通;

到此為止,好像路都成了堵死狀態(tài):prop值不能改->要用計(jì)算屬性;計(jì)算屬性不能改->需要setter;而寫(xiě)入了getter、setter,計(jì)算屬性的值依賴于prop值->prop值不能改?!粋€(gè)堪稱完美的閉環(huán)誕生了!

走投無(wú)路之際我想起了$emit和$on這一對(duì)。

3. 父子互相通信

前邊的prop實(shí)現(xiàn)了從父到子的單向通信,而通過(guò)$emit和$on,就可以實(shí)現(xiàn)從子組件到父組件的通信:這不能直接修改父組件的屬性,但卻可以觸發(fā)父組件的指定綁定事件,并將一個(gè)值傳入父組件。

在這一步我摒棄了點(diǎn)擊按鈕時(shí)的去操作子組件內(nèi)屬性的想法,既然計(jì)算屬性ifShowCancel依賴于prop值,那么就在點(diǎn)擊按鈕時(shí),通過(guò)$emit觸發(fā)父組件的事件,并將需要修改的屬性值傳入父組件,于是:

/*父組件自定義元素綁定switch-show事件*/
<t-header :showCancel=showCancel @switch-show="switchShow"></t-header>
// 父組件js
methods: {
 //會(huì)被子組件$emit觸發(fā)的方法
 switchShow(val) {
 this.showCancel = val;
 }
}
// 子組件js
methods: {
 //按鈕上的綁定click事件
 switchCancelBoard() {
 this.$emit("switch-show", this.ifShowCancel);
 }
}

這樣處理流程就變成了:點(diǎn)擊按鈕->作為計(jì)算屬性的ifShowCancel值傳入父組件并觸發(fā)父組件事件,對(duì)showCancel賦值->父組件屬性更新->觸發(fā)子組件prop更新->觸發(fā)重新compute,更新ifShowCancel值->v-show起作用。
另外在點(diǎn)擊其他區(qū)域時(shí),通過(guò)父組件綁定的click事件,就可以重置showCancel值,進(jìn)而隱藏掉出現(xiàn)的系統(tǒng)菜單。

下邊放出這個(gè)功能的完整代碼。

4. 完整代碼

/*父組件*/
<template>
 <p id="app" @click="hideCancel">
 <t-header :showCancel=showCancel @switch-show="switchShow"></t-header>
 <!-- <router-view/> -->
 </p>
</template>
<script>
 import THeader from "./components/t-header/t-header";
 export default {
 name: "app",
 components: {
 THeader
 },
 data() {
 return {
 showCancel: false
 };
 },
 methods: {
 hideCancel() {
 this.showCancel = false;
 },
 switchShow(val) {
 this.showCancel = val;
 }
 }
 };
</script>
<style scope lang="stylus">
</style>
/*子組件*/
<template>
 <p class="header-wrapper">
 <p class="title-wrapper">
 <p class="logo"></p>
 <h2 class="title">Title</h2>
 </p>
 <p class="info-wrapper">
 <span class="username">你好,管理員!</span>
 <span class="cancel" @click.stop="switchCancelBoard">
 <p class="cancel-p" v-show="ifShowCancel">
 <ul>
 <li @click.stop="doSomething" title="用戶設(shè)置">設(shè)置 </li>
 <li @click.stop="doSomething" title="退出登錄">退出 </li>
 </ul>
 </p>
 </span>
 </p>
 </p>
</template>
<script>
 export default {
 props: {
 showCancel: {
 type: Boolean
 }
 },
 methods: {
 doSomething() {},
 switchCancelBoard() {
 // this.ifShowCancel = !this.showCancel;
 this.$emit("switch-show", !this.ifShowCancel);
 }
 },
 computed: {
 ifShowCancel() {
 return this.showCancel;
 }
 }
 };
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
 .header-wrapper
 background: #1C60D1
 color: #fff
 width: 100%
 height: 50px
 line-height: 50px
 position: fixed
 top: 0px
 left: 0px
 font-size: 0
 .title-wrapper
 display: block
 position: relative
 float: left
 height: 50px
 .logo
 display: inline-block
 background-image: url('./logo.png')
 background-size: 30px 30px
 background-repeat: no-repeat
 width: 30px
 height: 30px
 margin-top: 10px
 .title
 display: inline-block
 font-size: 16px
 height: 50px
 line-height: 50px
 margin: 0px auto 0px 16px
 font-weight: normal
 vertical-align: top
 .info-wrapper
 display: block
 position: relative
 float: right
 height: 50px
 width: 160px
 font-size: 0
 .username
 display: inline-block
 height: 50px
 line-height: 50px
 font-size: 14px
 vertical-align: top
 .cancel
 display: inline-block
 vertical-align: middle
 background-image: url('./cancel.png')
 background-size: 32px 32px
 cursor: pointer
 background-repeat: no-repeat
 width: 32px
 height: 32px
 .cancel-p
 position: absolute
 display: block
 width: 60px
 height: 80px
 background: #fff
 z-index: 50
 top: 40px
 right: 16px
 font-size: 14px
 color: #646464
 box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.4)
 ul
 padding-left: 0px
 margin: 0px
 li
 width: 100%
 height: 40px
 line-height: 40px
 text-align: center
 list-style-type: none
 &:hover
 background-color: #eaeaea
</style>

相信看了本文案例你已經(jīng)掌握了方法,更多精彩請(qǐng)關(guān)注Gxl網(wǎng)其它相關(guān)文章!

推薦閱讀:

怎樣使用vue mint-ui tabbar(附代碼)

怎樣使用Vue結(jié)合Video.js播放m3u8視頻

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

怎樣使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單

怎樣使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單:這次給大家?guī)?lái)怎樣使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單,使用Vue在頁(yè)面右上角實(shí)現(xiàn)可懸浮/隱藏菜單的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來(lái)看一下。這是個(gè)大多數(shù)網(wǎng)站很常見(jiàn)的功能,點(diǎn)擊頁(yè)面右上角頭像顯示一個(gè)懸浮菜單,點(diǎn)擊頁(yè)面其他位置或再次點(diǎn)擊頭
推薦度:
標(biāo)簽: 使用 菜單 VUE
  • 熱門(mén)焦點(diǎn)

最新推薦

猜你喜歡

熱門(mén)推薦

專題
Top
主站蜘蛛池模板: 会理县| 宝坻区| 砚山县| 东兴市| 海城市| 阳春市| 江安县| 建水县| 容城县| 陈巴尔虎旗| 古丈县| 汉寿县| 邹平县| 金门县| 青阳县| 扎鲁特旗| 霍林郭勒市| 建湖县| 寿宁县| 桦川县| 娄烦县| 泾源县| 大荔县| 兴安县| 临海市| 塘沽区| 边坝县| 驻马店市| 方正县| 鄯善县| 金坛市| 英吉沙县| 郴州市| 三河市| 彭州市| 安图县| 小金县| 如皋市| 文昌市| 辽宁省| 鹿邑县|