c2 點擊雙向切換網址

by BDeer

HTML

<div id="app">
 <a :href="src">{{ message }}</a>
 <button @click="changeSrc">雙向切換</button>      
</div>

CSS

a{color:#111;text-decoration:none;}
a:hover{text-decoration:underline}

Vue

let vmBindeOn = new Vue({
 el: '#app',
 data: {
  isActive:true,
  message:'雅虎奇摩',
  src:'https://tw.yahoo.com/'          
 },
 methods:{
  changeSrc(){
   this.isActive = !this.isActive
   if(this.isActive == true){
    this.message = '雅虎奇摩';
    this.src = 'https://tw.yahoo.com/';
   } else {                        
    this.message = '地球圖輯隊';
    this.src = 'https://dq.yam.com/list.php'
   }
  }
 }
})