標籤:ref bin child outline 變化 for lock radius font
vue.js實現按鈕的動態綁定
實現效果:
實現代碼以及注釋:
<!DOCTYPE html><html><head><title>按鈕綁定</title><meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><style type="text/css">*{margin: 0;padding: 0;}body{font: 15px/1.3 ‘Open Sans‘, sans-serif;color: #5e5b64;text-align: center;}a, a:visited{outline: none;color: #3b9dc1;}a:hover{text-decoration: none;}section, footer, header, aside, nav{display: block;}/* 功能表列 */nav{display: inline-block;margin: 60px auto 45px;background-color: #5597b4;box-shadow: 0 1px 1px #ccc;border-radius: 2px;}nav a{display: inline-block;padding: 18px 30px;color: #fff !important;font-weight: bold;font-size: 16px;text-decoration: none !important;line-height: 1;text-transform: uppercase;background-color: transparent;-webkit-transition:background-color 0.25s;z-index: moz-transition:background-color 0.25s;transition:background-color 0.25s;}nav a:first-child{border-radius:2px 0 0 2px;}nav a:last-child{border-radius:0 2px 2px 0;}nav.home .home,nav.projects .projects,nav.services .services,nav.contact .contact{background-color:#e35885;}p{font-size:22px;font-weight:bold;color:#7d9098;}p b{color:#ffffff;display:inline-block;padding:5px 10px;background-color:#c4d7e0;border-radius:2px;text-transform:uppercase;font-size:18px;}</style></head><body><div id="main"><!--導覽列菜單會得到處於active的變數的值作為一個class --><!-- 為了防止當我們點選連結時頁面發生跳轉,我們使用prevent最佳化 --><nav v-bind:class="active" v-on:click.prevent><!-- 當一個菜單中的連結被點擊,我們調用定義在javaScript vue中的makeActive方法 --><a href="#" class="home" v-on:click="makeActive(‘home‘)">Home</a><a href="#" class="projects" v-on:click="makeActive(‘projects‘)">Projects</a><a href="#" class="services" v-on:click="makeActive(‘services‘)">Services</a><a href="#" class="contact" v-on:click="makeActive(‘contact‘)">Contact</a></nav><!-- mustache運算式將被active的值替換,它將發生任何變化它都將會自動更新--><p>YOU SELECTED <b>{{active}}</b></p></div><script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.5/vue.min.js"></script><script type="text/javascript">// 建立一個Vue樣本,並且傳遞一個可選對象var demo = new Vue({// 一個DOM元素表示我們的view模型el: ‘#main‘,// 定義屬性值,給定初始化值data: {active: ‘home‘},// 我們需要使用到的函數methods: {makeActive: function(item){// 當一個model發生變化,view會自動更新this.active = item;}}});</script></body></html>
【前端】vue.js實現按鈕的動態綁定