vue.js
来源:互联网 发布:淘宝卖家的联系 编辑:程序博客网 时间:2024/05/16 19:12
案例知识点:
1.vue.js基础知识
2.HTML5 本地存储localstorage
store.js代码
const STORAGE_KEY = 'todos-vue.js'export default{ fetch(){ return JSON.parse(window.localStorage.getItem(STORAGE_KEY) || '[]') }, save(items){ window.localStorage.setItem(STORAGE_KEY,JSON.stringify(items)); }}
App.vue代码
<template> <div id="app"> <h1 v-text="title"></h1> <input v-model="newItem" v-on:keyup.enter="addNew"/> <ul> <li v-for="item in items" v-bind:class="{finished:item.isFinished}" v-on:click='toogleFinish(item)'> {{item.label}} </li> </ul> </div></template><script>import Store from './store'export default { name: 'app', data () { return { title: 'this is a todo list', items:Store.fetch(), newItem:'' } }, watch:{ items:{ handler(items){ //经过变化的数组会作为第一个参数传入 Store.save(items) console.log(Store.fetch()); }, deep:true //深度复制 } }, methods:{ toogleFinish(item){ item.isFinished = !item.isFinished }, addNew(){ this.items.push({ label:this.newItem, isFinished:false, }) this.newItem = '' } }}</script><style>#app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px;}.finished{ text-decoration: underline;}</style>
阅读全文
0 0
- vue.js
- vue.js
- vue.js
- Vue.js
- vue.js
- Vue.js
- vue.js
- vue.js
- vue.js
- Vue.js
- vue.js
- Vue.js
- Vue.js
- Vue.js
- Vue.js
- Vue.js
- Vue.js
- vue.js
- 腾讯和阿里正在如何塑造一个中国互联网的众神时代
- 谁说装博会不好玩?3D全景海报,机器人嘉年华,义乌装博会大打人工智能牌
- 激发日二极管和亚国家;在
- HDU4055 Number String(计数dp)
- 两行Python代码实现电影打分与推荐
- vue.js
- 乐视董事长贾跃亭起诉顾颖琼造谣诽谤
- 全球最有价值的100个品牌中,科技公司有哪些?
- 继韩国之后,大疆在日本再成立无人机练习场
- 科沃斯机器人登陆苏宁 开启智慧零售新高度
- 一个二维码所引起的战争,阿里、腾讯被诉侵权
- 求数组的最长递减子序列 (dp)
- 科普:百度利用WI-FI探针收集和泄露用户隐私?你可能想多了
- 抢领英饭碗?Facebook测试简历功能