<template>
<div id="app">
<h1 v-html = "title"></h1>
<input v-model="newItem" v-on:keyup.enter="addNew" ></input>
<ul>
<li v-for="item in items" v-bind:class="{finished:item.isFinished}" v-on:click="toggleFinish(item)">{{item.label}}</li>
</ul>
</div>
</template>
<script>
import Store from './store'
export default {
data:function(){
return {
title:"This Is A Todolist",
items:Store.fetch(),
newItem:""
}
},
watch:{
items:{
handler:function(items){
Store.save(items)
},
deep:true
}
},
methods:{
toggleFinish:function(item){
item.isFinished = !item.isFinished
},
addNew:function(){
this.items.push({
label:this.newItem,
"isFinished":false
})
this.newItem=""
}
}
}
</script>
<style>
.finished{
text-decoration:underline;
}
li{
list-style:none;
font-size:1.6em;
margin-top:10px;
}
#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;
}
input{
width:230px;
height:40px;
border-radius:20px;
padding: 0.4em 0.35em;
border:3px solid #CFCFCF;
font-size: 1.55em;
}
</style>
const STORAGE_KEY='todos-vuejs'
export default {
fetch:function(){
return JSON.parse(window.localStorage.getItem(STORAGE_KEY)||'[]');
},
save:function(items){
window.localStorage.setItem(STORAGE_KEY,JSON.stringify(items))
}
}
export default {
name: 'hello',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
//demo1.js
export const str = 'hello world'
export function f(a){ return a+1}
对应的导入方式:
//demo2.js
import { str, f } from 'demo1' //也可以分开写两次,导入的时候带花括号
//demo1.js export default const str = 'hello world' 对应的导入方式: //demo2.js import str from 'demo1' //导入的时候没有花括号
<template>
<div id="app">
<h1 v-html = "title"></h1>
<ul>
<li v-for="item in items" v-bind:class="{finished:item.isFinished}">{{item.label}}</li>
</ul>
</div>
</template>
<script>
import Hello from './components/Hello'
export default {
data:function(){
return {
title:"this is a todolist",
items:[
{
label:"coding",
"isFinished":false
},
{
label:"walking",
"isFinished":true
}
]
}
}
}
</script>
<style>
.finished{
text-decoration:underline;
}
#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;
}
</style>
methods:{
toggleFinish:function(item){
item.isFinished = !item.isFinished
}
}
<input v-model="newItem" v-on:keyup.enter="addNew" ></input>
newItem:""
//addNew:function(){
// alert(this.newItem)
// this.newItem="" //添加后加输入框清空
//}
addNew:function(){
this.items.push({
label:this.newItem,
"isFinished":false
})
this.newItem=""
}
const STORAGE_KEY='todos-vuejs'
export default {
fetch:function(){
return JSON.parse(window.localStorage.getItem(STORAGE_KEY)||'[]');
},
save:function(items){
window.localStorage.setItem(STORAGE_KEY,JSON.stringify(items))
}
}
import Store from './store'
watch:{
items:{
handler:function(val,oldVal){
console.log(val,oldVal)
},
deep:true
}
},
watch:{
items:{
handler:function(items){
Store.save(items)
},
deep:true
}
},
<script>
import Store from './store'
export default {
data:function(){
return {
title:"<span>?</span>this is a todolist",
items:Store.fetch(),
newItem:""
}
},
watch:{
items:{
handler:function(items){
Store.save(items)
},
deep:true
}
},
methods:{
toggleFinish:function(item){
item.isFinished = !item.isFinished
},
addNew:function(){
this.items.push({
label:this.newItem,
"isFinished":false
})
this.newItem=""
}
}
}
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有