vue實(shí)現(xiàn)導(dǎo)航菜單和編輯文本的示例代碼
導(dǎo)航菜單實(shí)例
<div id="main">
<!-- 激活的菜單樣式為 active 類 -->
<!-- 為了阻止鏈接在點(diǎn)擊時(shí)跳轉(zhuǎn),我們使用了 "prevent" 修飾符 (preventDefault 的簡(jiǎn)稱)。 -->
<nav v-bind:class="active" v-on:click.prevent>
<!-- 當(dāng)菜單上的鏈接被點(diǎn)擊時(shí),我們調(diào)用了 makeActive 方法, 該方法在 Vue 實(shí)例中創(chuàng)建。 -->
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="home" v-on:click="makeActive('home')">Home</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="projects" v-on:click="makeActive('projects')">Projects</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="services" v-on:click="makeActive('services')">Services</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="contact" v-on:click="makeActive('contact')">Contact</a>
</nav>
<!-- 以下 "active" 變量會(huì)根據(jù)當(dāng)前選中的值來自動(dòng)變換 -->
<p>您選擇了 <b>{{active}} 菜單</b></p>
</div>
<script>
// 創(chuàng)建一個(gè)新的 Vue 實(shí)例
var demo = new Vue({
// DOM 元素,掛載視圖模型
el: '#main',
// 定義屬性,并設(shè)置初始值
data: {
active: 'home'
},
// 點(diǎn)擊菜單使用的函數(shù)
methods: {
makeActive: function(item){
// 模型改變,視圖會(huì)自動(dòng)更新
this.active = item;
}
}
});
</script>
效果如下:

編輯文本實(shí)例
<!-- v-cloak 隱藏未編譯的變量,直到 Vue 實(shí)例準(zhǔn)備就緒。 -->
<!-- 元素點(diǎn)擊后 hideTooltp() 方法被調(diào)用 -->
<div id="main" v-cloak v-on:click="hideTooltip">
<!-- 這是一個(gè)提示框
v-on:click.stop 是一個(gè)點(diǎn)擊事件處理器,stop 修飾符用于阻止事件傳遞
v-if 用來判斷 show_tooltip 為 true 時(shí)才顯示 -->
<div class="tooltip" v-on:click.stop v-if="show_tooltip">
<!-- v-model 綁定了文本域的內(nèi)容
在文本域內(nèi)容改變時(shí),對(duì)應(yīng)的變量也會(huì)實(shí)時(shí)改變 -->
<input type="text" v-model="text_content" />
</div>
<!-- 點(diǎn)擊后調(diào)用 "toggleTooltip" 方法并阻止事件傳遞 -->
<!-- "text_content" 變量根據(jù)文本域內(nèi)容的變化而變化 -->
<p v-on:click.stop="toggleTooltip">{{text_content}}</p>
</div>
<script>
var demo = new Vue({
el: '#main',
data: {
show_tooltip: false,
text_content: '點(diǎn)我,并編輯內(nèi)容。'
},
methods: {
hideTooltip: function(){
// 在模型改變時(shí),視圖也會(huì)自動(dòng)更新
this.show_tooltip = false;
},
toggleTooltip: function(){
this.show_tooltip = !this.show_tooltip;
}
}
})
</script>
效果如下:

以上就是vue實(shí)現(xiàn)導(dǎo)航菜單和編輯文本的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于vue 導(dǎo)航菜單 編輯文本的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- Vue使用element-ui實(shí)現(xiàn)菜單導(dǎo)航
- ant design vue導(dǎo)航菜單與路由配置操作
- Vue實(shí)現(xiàn)導(dǎo)航欄菜單
- vue 導(dǎo)航菜單刷新狀態(tài)不消失,顯示對(duì)應(yīng)的路由界面操作
- 解決vue項(xiàng)目刷新后,導(dǎo)航菜單高亮顯示的位置不對(duì)問題
- vue二級(jí)菜單導(dǎo)航點(diǎn)擊選中事件的方法
- vuejs 切換導(dǎo)航條高亮(路由菜單高亮)的方法示例
- Vue-路由導(dǎo)航菜單欄的高亮設(shè)置方法
- vue2.0實(shí)現(xiàn)導(dǎo)航菜單切換效果
- vue.js使用Element-ui實(shí)現(xiàn)導(dǎo)航菜單
相關(guān)文章
vue的rules驗(yàn)證部分可以部分又失效的原因及解決方案
vue的rules驗(yàn)證失效,部分可以部分又失效,很多百度都有,但是我這里遇到了一個(gè)特別的,那就是prop沒有寫全,導(dǎo)致驗(yàn)證某一個(gè)失效,接下來就跟小編一起來看看這個(gè)失效的原因和解決方案吧2023-11-11
vue3源碼剖析之簡(jiǎn)單實(shí)現(xiàn)方法
源碼的重要性相信不用再多說什么了吧,特別是用Vue 框架的,一般在面試的時(shí)候面試官多多少少都會(huì)考察源碼層面的內(nèi)容,下面這篇文章主要給大家介紹了關(guān)于vue3源碼剖析之簡(jiǎn)單實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2021-09-09
vue登錄頁實(shí)現(xiàn)使用cookie記住7天密碼功能的方法
這篇文章主要介紹了vue登錄頁實(shí)現(xiàn)使用cookie記住7天密碼功能的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
vue.nextTick()與setTimeout的區(qū)別及說明
這篇文章主要介紹了vue.nextTick()與setTimeout的區(qū)別及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
vue2如何實(shí)現(xiàn)vue3的teleport
這篇文章主要介紹了vue2如何實(shí)現(xiàn)vue3的teleport,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
vuex存儲(chǔ)復(fù)雜參數(shù)(如對(duì)象數(shù)組等)刷新數(shù)據(jù)丟失的解決方法
今天小編就為大家分享一篇vuex存儲(chǔ)復(fù)雜參數(shù)(如對(duì)象數(shù)組等)刷新數(shù)據(jù)丟失的解決方法。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11

