<div id="app">
<input type="text" class="form-control" @keydown.enter="reverseText" v-model="text">
<button class="btn btn-primary mt-1" v-on:click="reverseText">反轉字串</button>
<div class="mt-3">
{{ newText }}
</div>
<a :href="link" class="btn btn-primary mt-1" v-on:click.prevent="reverseText">反轉字串</button>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
//這邊需先定義好變數名稱
text: '',
newText: '',
link:'www.google.com'
},
methods:{
reverseText(){
console.log(this.text);
this.newText = this.text.split('').reverse().join('');
}
}
// 請在此撰寫 JavaScript
});
</script>