半岛铁盒

生活、技术个人博客


  • 首页

  • 分类

  • 归档

  • 标签

  • 关于

vue-router 应用

发表于 2017-12-10 | 分类于 Vue | | 阅读次数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.9/vue.js"></script>
<script src="https://unpkg.com/vue-router@2.5.3/dist/vue-router.js"></script>
<style>
#app{width: 1000px;height: 800px;box-shadow: 2px 2px 10px #ccc;margin: 0 auto}
.nav{width: 500px;height: 300px;border:1px solid #efefef;box-shadow: 0px 0px 10px #ccc;float: left;}
.nav a{width: 100%;line-height: 60px;border-bottom: 1px solid #efefef;display: block;text-align: center;}
.content{width: 400px;height:200px;float: right;line-height: 200px;text-align: center;color: #333;}
</style>
</head>
<body>
<div id="app">
<div class="nav">
<!-- <a>简单的vue</a>
<a>这是es6</a>
<a>这是webpack</a> -->
<router-link to="/vue">vue</router-link>
<router-link to="/es6">es6</router-link>
<router-link to="/webpack">webpack</router-link>
</div>
<div class="content">
<router-view></router-view>
</div>
</div>
<script>
const vueComponent = {
template:`<div>
这里是《简易vue》教程
</div>`
};

//2.趣味ES6 对应的视图组件
const es6Component = {
template:`<div>
这里是《趣味ES6》教程
</div>`
};

//3.人在职场 对应的视图组件
const careerComponent = {
template:`<div>
《混口饭吃》与《工资待遇》
</div>`
};


// 创建router实例,定义导航和组件之间的映射关系
const router = new VueRouter({
routes:[
{
path:"/vue",
component:vueComponent
},
{
path:"/es6",
component:es6Component
},
{
path:"/webpack",
component:careerComponent
},
]
});




let app=new Vue({
el:"#app",
router
})
</script>
</body>
</html>

vue-transition组件

发表于 2017-12-10 | 分类于 Vue | | 阅读次数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.9/vue.js"></script>
<style>
#app{width:400px;height: 400px;border:1px solid #efefef;box-shadow: 2px 2px 10px #ccc;margin: 0 auto;position: relative}
button{width: 10%;height: 35px;line-height: 35px;box-sizing: border-box;border-radius: 4px;background:red;color: #fff;border: none;margin: 0 auto;margin-top: 50px;}
.container{width: 200px;height: 200px;border:1px solid #efefef;box-shadow: 5px 5px 10px #ccc;margin: 0 auto;margin-top: 20px;}
.box{width: 200px;height: 200px;background: #000;opacity: 1;margin-left: 0px;}
.box-enter-active,.box-leave-active{transition: all 0.8s;}
.box-enter{opacity: 0;margin-left: 200px;}
.box-leave-active{opacity: 0;margin-left: 200px;}
</style>
</head>
<body>
<div id="app">
<button @click="show">切换</button>
<div class="container">
<transition name="box">
<div class="box" v-show="showBox"></div>
</transition>

</div>

</div>
<script>
let app=new Vue({
el:"#app",
data:{
showBox:true
},
methods:{
show(){
this.showBox=(!this.showBox)
}
}
})
</script>
</body>
</html>

vue开发调试神器

发表于 2017-12-10 | 分类于 Vue | | 阅读次数

1.谷歌插件 vue.js Devool
2.chorme:verson 查看安装地址,个人安装路径 extions
3.允许访问网址
4.重启刷新
举例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- <script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.9/vue.js"></script>

<style>
#app{width: 1000px;margin: 0 auto}
.ainput{ display:inline-block ;
width:10%;
height: 35px;
line-height: 35px;
margin: 30px auto;
box-sizing: border-box;
padding-left: 4px;
border-radius: 4px;
border:1px solid #ccc;
outline: 0;
box-shadow: 0 0 5px #ccc;}
.del{width: 10%;height: 35px;line-height: 35px;box-sizing: border-box;border-radius: 4px;background:red;color: #fff;border: none;}
</style>
</head>
<body>
<div id="app">
<input type="text" class="ainput" v-model='augend' @keyup="comput">
<span>+</span>
<input type="text" class="ainput" v-model='addend' @keyup="comput">
<span>=</span>
<input type="text" class="ainput" :value="sum">
<br>
<button class="del" @click="rest">清空数据</button>
</div>
<script>
const app=new Vue({
el:"#app",
data:{
augend:'',
addend:'',
sum:''
},
methods:{
comput(){
this.sum=Number(this.augend)+Number(this.addend)
},
rest(){
this.sum=this.addend=this.augend='';
this.$emit('rest')
}
}
})
</script>
</body>
</html>

vue实战-小案例

发表于 2017-12-07 | 分类于 Vue | | 阅读次数

加强动手能力是进步的最好方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
<style>
.demo{width: 400px;height: 600px;border: 1px solid #ccc;margin: 0 auto;}
.edit{
display:block ;
width:80%;
height: 35px;
line-height: 35px;
margin: 30px auto;
box-sizing: border-box;
padding-left: 4px;
border-radius: 4px;
border:1px solid #ccc;
outline: 0;
box-shadow: 0 0 5px #ccc;
}
.list{margin: 0 auto;width: 80%}
.unit{position: relative;padding: 10px 0;border-bottom: 1px solid #efefef;}
.unit:last-child{border-bottom: 0;}
.finish{text-decoration:line-through;color: #ccc;}
.del{background: red;
text-decoration: none;
position: absolute;
right:0;
font-size: 12px;
border: 0;
outline: 0;
padding: 2px 5px;
border-radius: 5px;
color: #fff;}
.empty{ font-size: 13px;
color: #ccc;
text-align: center;
padding: 10px 0;}
</style>
</head>
<body>
<div id="app" class="demo">
<input class="edit" v-model="task.content" type="text" placeholder="编写任务" @keydown.enter='addTask' >

<div class="list">
<div class="unit" v-for="(item,index) in list">
<input type="checkbox" @click='change(index)' :checked="item.finished">
<span :class="{finish:item.finished}">{{item.content}}</span>
<button class="del" @click='del(index)'>删除</button>
</div>
<p class="empty" v-if="list.length===0">暂无任务</p>
</div>
</div>
<script>
const vm=new Vue({
el:"#app",
data:{
//默认
task:{
content:'',//内容为空
finished:false,//未完成
deleted:false//未删除
},


//任务列表
list:[]
},


methods:{
addTask(){
this.list.push(this.task);

this.task={
content:'',
finished:false,//是否完成
deleted:false //是否删除
}
},

change(index){
let curstate=this.list[index].finished;
this.list[index].finished=!curstate;
},

del(index){
this.list.splice(index,1)
}
}
})

</script>
</body>
</html>
1…678…18
Jksen zhangxing

Jksen zhangxing

酝酿中....

69 日志
11 分类
33 标签
RSS
GitHub 微博
Links
  • 我的站点
© 2020 Jksen zhangxing
由 Hexo 强力驱动
主题 - NexT.Mist