- Vue.js 2 Web Development Projects
- Guillaume Chau
- 107字
- 2021-07-02 22:34:26
Using a method
There is a good coding principle that says Don't Repeat Yourself, and we really should follow it. That's why we can write some logic in reusable functions called methods. Let's move our saving logic into one:
- Add a new methods option to the Vue instance and use the localStorage API there:
new Vue({ // ... methods: { saveNote (val) { console.log('saving note:', val) localStorage.setItem('content', val) }, }, })
- We can now use the method name in the handler option of our watcher:
watch: { content: { handler: 'saveNote', }, },
Alternatively, we can use it with the shorter syntax:
watch: { content: 'saveNote', },
推薦閱讀
- SPSS數據挖掘與案例分析應用實踐
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- Progressive Web Apps with React
- Raspberry Pi for Secret Agents(Third Edition)
- Cassandra Data Modeling and Analysis
- FPGA Verilog開發實戰指南:基于Intel Cyclone IV(進階篇)
- Windows內核編程
- 從零開始學C#
- 軟件供應鏈安全:源代碼缺陷實例剖析
- HoloLens與混合現實開發
- OpenCV 3計算機視覺:Python語言實現(原書第2版)
- Backbone.js Testing
- Oracle 12c從入門到精通(視頻教學超值版)
- INSTANT Apache ServiceMix How-to
- 從零開始構建深度前饋神經網絡:Python+TensorFlow 2.x