- Vue.js Quick Start Guide
- Ajdin Imsirovic
- 185字
- 2021-06-24 18:23:56
Vue methods
The methods option in a Vue instance just lists all the functions that exist on that Vue instance (or on a Vue component).
The methods option works with the data of the Vue instance. What follows is a simple demonstration of this concept in practice:
// HTML
<div id="definitions">
<!-- 'whatIsVue' and 'whyUseVue' are functions defined in the 'methods' option in the Vue instance -->
<button id="btn" v-on:click="whatIsVue">What is Vue?</button>
<button id="btn" v-on:click="whyUseVue">Why use Vue?</button>
</div>
// JS
var definitions = new Vue({
el: '#definitions',
data: {
name: 'Vue.js'
},
// define methods (functions) under the `methods` object
methods: {
whatIsVue: function () {
console.info(this.name + ' is a Progressive Front-end Framework')
},
whyUseVue: function () {
alert('Because ' + this.name + ' is nice.')
}
}
})
As we can see, the data option holds the Vue.js string, which can be accessed via the name key.
Inside the methods option, we can see two functions: whatIsVue and whyUseVue. The whatIsVue function takes the click event and logs out the value inside name to the console. The whyUseVue function inside the methods option works similarly.
This code can be seen in a pen at this address: https://codepen.io/AjdinImsirovic/pen/yEPXdK.
推薦閱讀
- 物聯網短距離無線通信技術應用與開發
- Truffle Quick Start Guide
- 異構基因共表達網絡的分析方法
- Hands-On Industrial Internet of Things
- 走進物聯網
- 信息通信網絡建設安全管理概要2
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 區塊鏈輕松上手:原理、源碼、搭建與應用
- 計算機網絡原理與應用技術
- IPv6網絡切片:使能千行百業新體驗
- 光纖通信系統與網絡(修訂版)
- 5G非正交多址接入技術:理論、算法與實現
- 計算機通信網絡安全
- 信息技術安全評估準則:源流、方法與實踐
- 網絡安全和信息化黨政領導干部一本通