
Vue.js概述
MVVM模型

Hello Vue
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="../sources/vue.js"></script>
</head>
<body>
<div id="app">
<h1>{{message}}</h1>
</div>
<script>
var vm = new Vue({
el: "#app",
data:{
message:"Hello,Vue!"
}
});
</script>
</body>
</html>
缩写 v-bind & v-on
Vue的7个属性
双向数据绑定
组件


<div id="app">
<wei_shuo v-for="item in items" v-bind:wei="item"></wei_shuo>
</div>
<script>
<!--定义一个Vue组件component-->
Vue.component("wei_shuo", {
props:['wei'],
template: '<li>{{wei}}</li>'
});
var vm = new Vue({
el: "#app",
data: {
items: ["Java","Linux","前端","后端"]
}
});
</script>
Axios异步通讯
背景
Vue声明周期

声明周期钩子函数
内容分发(Slot插槽)

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="../sources/vue.js"></script>
</head>
<body>
<div id="app">
<todo>
<todo-title slot="todo-title" v-bind:title="title1"></todo-title>
<todo-items slot="todo-items" v-for="item1 in todoItems" :item="item1"></todo-items>
</todo>
</div>
<script>
<!--定义插槽-->
Vue.component("todo", {
template:
'<div>' +
'<slot name="todo-title"></slot>' +
'<ul>' +
'<slot name="todo-items"></slot>' +
'</ul>' +
'</div>'
});
Vue.component("todo-title",{
props:['title'],
template: '<div>{{title}}</div>'
});
Vue.component("todo-items",{
props: ['item'],
template: '<li>{{item}}</li>'
});
var vm = new Vue({
el: "#app",
data:{
title1:"wei_shou列表",
todoItems:['学习Java','学习Linux','学习Vue']
}
})
</script>
</body>
</html>
自定义事件($emit)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="../sources/vue.js"></script>
</head>
<body>
<div id="app">
<todo>
<todo-title slot="todo-title" v-bind:title="title1"></todo-title>
<todo-items slot="todo-items" v-for="(item1,index) in todoItems" :item="item1" v-bind:index="index"
v-on:remove="removeItems(index)" v-bind:key="index"></todo-items>
</todo>
</div>
<script>
<!--定义插槽-->
Vue.component("todo", {
template:
'<div>' +
'<slot name="todo-title"></slot>' +
'<ul>' +
'<slot name="todo-items"></slot>' +
'</ul>' +
'</div>'
});
Vue.component("todo-title", {
props: ['title'],
template: '<div>{{title}}</div>'
});
Vue.component("todo-items", {
props: ['item', 'index'],
template: '<li>{{index}}---{{item}}<button @click="remove">删除</button></li>',
methods: {
remove: function (index) {
this.$emit('remove', index)
}
}
});
var vm = new Vue({
el: "#app",
data: {
title1: "wei_shou列表",
todoItems: ['学习Java', '学习Linux', '学习Vue'],
removeItems: function (index) {
console.log("删除" + this.todoItems[index] + "OK")
this.todoItems.splice(index, 1);
}
}
})
</script>
</body>
</html>
vue-cli项目
初始化运行
IDEA搭建vue-cli项目
Webpack学习
安装Webpack

测试安装成功

配置
webpack使用
vue-router路由
安装vue-router
测试
vue-router使用
创建公共组件目录components
创建存放路由的文件夹router
配置路由
使用路由
vue-router使用流程
结果测试
Axios
安装
$ npm install axios
Vue+ElementUI
创建工程
项目搭建

排错分析
排错一

排错二

Module build failed: Error: Node Sass version 8.0.0 is incompatible with ^4.0.0.
排错三

Module build failed: Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (93)

排错四

"export 'default' (imported as 'Router') was not found in 'vue-router'
排错总结
运行项目
vue项目目录分析
npm命令解析
路由嵌套
/user/johnny/profile /user/johnny/posts
+------------------+ +-----------------+
| User | | User |
| +--------------+ | | +-------------+ |
| | Profile | | +------------> | | Posts | |
| | | | | | | |
| +--------------+ | | +-------------+ |
+------------------+ +-----------------+
项目结构

路由模式
export default new Router({
mode:'history',
routes: [
]
});
参数传递&重定向
参数传递
重定向
export default new Router({
mode:'history',
routes: [
{
path:'/goHome',
redirect:'/main'
}
]
});
404页面
路由钩子&异步请求
路由钩子
<script>
export default {
beforeRouteEnter:(to,from,next)=>{
console.log("STARE");
next();
},
beforeRouteLeave:(to,from,next)=>{
console.log("END");
next();
}
}
</script>
异步请求
Vue工程化项目目录结构
