Vue.config.productionTip = false; 是否显示提示信息

import/export

export xxx 必须跟跟对象或者和定义一起

对象: export {xxxx}

定义: export let a = xxx;

    export function(){}


引入:

import modA from "./a" 错误

import {a} from "./a"

导出:

a.js

let a = 12;

export a;错误

export {a}


引入:

import modA from "./a" // modA => {a:12}

导出:

a.js

let a = 12;

export default {a}


导出:

export let a = "a";

等价于

let a = "a";

export {a};

引入:

import {a} from "./a"


导出:

let a = "a"

export default {a};

等价于

export default {a:"a"};

引入:

import modA from "./a";


导出

export var a = "a";

export var b = "b";

export var c = "c";

导入

import modA from "./a";错误

import * as modA from "./a";

console.log("modA",modA,modA.a,modA.b,modA.c);

或:

import {a,b,c} from "./a";

console.log("modA",a,b,c);


导出:

let a = "a";

let b = "b";

let c = "c";

export default {a,b,c}

导入

import modA from "./a";

console.log("modA",modA,modA.a,modA.b,modA.c);


export default 导出去的东西

引入的时候可以取任意的名字

++一个模块 只能有一个default++


导出

export default function(){

  alert("fn1");

};

export let a = 1;

export let b = 2;

export let c = 3;

引入:

import * as all from "./a";

// 接收所有

console.log("0modA",all,all.default,all.a,all.b,all.c);

import modA from "./a";

//获取的default出去的东西

console.log("1modA",modA);

import {a,b,c} from "./a";

console.log("2modA", a,b,c);

==>合并

import modA,{a,b,c} from "./a";

console.log("2modA",modA, a,b,c);


导出

export default {a:1};

export let b = "b";

引入

import modA from "./a";

console.log("2modA",modA);

setTimeout(()=>{

   import("./a").then(res=>{

    console.log("then:",res,res.default,res.b);

});

sass/less/css

sass:$

less:@

sass:安装 cnpm i -S sass-loader node-sass

.sass

.scss

less:安装 cnpm i -S less-loader less

样式里面配置 lang="scss/less"


运动/动画

原生写法
两部分:进入enter、离开leave

enter ---->none-->block 显示的过程

leave ---->block-->none 消失的过程

动画原生写法

xxx-enter{}        开始的状态
xxx-enter-active{} 运动形态
xxx-enter-to{} 终点 xxx-leave{} 离开的开始的状态
xxx-leave-active{} 运动形态
xxx-leave-to{} 离开终点

exp1:留言板一

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#div1{width:200px; height: 200px; background: #ccc;} .fade-enter{opacity: 0;}
.fade-enter-active{ transition: 1s all ease;}
.fade-enter-to{opacity: 1;} .fade-leave{opacity: 1;}
.fade-leave-active{transition: 1s all ease;}
.fade-leave-to{opacity: 0;}
</style>
<script src = "vue.js"></script>
<script>
window.onload = function(){
let vm = new Vue({
el:"#app",
data:{
isShow:true,
},
methods:{
showHide(){
this.isShow = !this.isShow;
}
}
})
}
</script>
</head>
<body>
<div id="app">
<input @click="showHide" type="button" value="显示隐藏"/> <transition name="fade">
<div id="div1" v-show="isShow"></div>
</transition>
</div>
</body>
</html>
使用自定义的动画名称
enter-class = "xxx"
enter-active-class = "xxx"
enter-to-class = "xxx" leave-class = "xxx"
leave-active-class = "xxx"
leave-to-class = "xxx"

exp2:留言板二

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
*{marign:0;padding:0;list-style:none;} ul{width:300px; overflow: hidden; border:1px solid green;}
ul li{ text-indent: 2em; height:50px; line-height: 50px; border-bottom: 1px dashed red;}
ul li:nth-last-child(1) { border-bottom:none;} .fade-slide-enter{opacity:0;height: 0;}
/*.fade-slide-enter-active{ transition: 1s all ease;}*/ .fade-slide-in-active{ transition: 1s all ease;}
.fade-slide-enter-to{opacity:1;height: 50px;} .fade-slide-leave{opacity:1;height: 50px;}
/*.fade-slide-leave-active{transition: 1s all ease;}*/
.fade-slide-out-active{transition: 1s all ease;}
.fade-slide-leave-to{opacity:0;height: 0;} </style>
<script src="vue.js"></script>
<script>
window.onload = function(){
let vm = new Vue({
el:"#app",
data:{
msg:"abc",
arr:["aaa","bbb","ccc"]
},
methods:{
add(){
this.arr.push(this.msg);
},
/*del(index){
this.arr.splice(index,1)
} */
del(item){
this.arr = this.arr.filter(value=>{
return item != value;
});
}
}
});
};
</script>
</head> <body>
<div id="app">
<input v-model="msg" type="text" value=""/>
<input @click="add" type="button" value="添加"/>
<ul>
<transition-group name="fade-slide"
enter-active-class="fade-slide-in-active"
leave-active-class="fade-slide-out-active"
>
<li v-for="item,index in arr" :key="item">{{item}}<a @click="del(item)" href="javascript:;">删除</a></li>
</transition-group>
</ul> </div>
</body>
</html>
运动:

transition:只能作用一个元素 要多个元素需要使用 transition-group

<transition/transition-group name="指定动画的名称" enter-active-class="自定义的动画样式名称">

</transition/transition-group>

使用animate.css:

1、animated添加到 transition标签上

<transition enter-active-class="animated xxx">
<div>动画的元素</div>
</transition>

2、animated添加到 transition动画的元素上

<transition>
<div class="animated"></div>
</transition>

exp3:留言板三

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<link rel="stylesheet" href="animate.css"/>
<style>
*{margin:0;padding:0;list-style:none;} ul{width:300px; overflow: hidden; border:1px solid green;}
ul li{ text-indent: 2em; height:50px; line-height: 50px; border-bottom: 1px dashed red;}
ul li:nth-last-child(1) { border-bottom:none;} </style>
<script src="vue.js"></script>
<script>
window.onload = function(){
let vm = new Vue({
el:"#app",
data:{
msg:"abc",
arr:["aaa","bbb","ccc"]
},
methods:{
add(){
this.arr.push(this.msg);
},
del(item){
this.arr = this.arr.filter(value=>{
return item != value;
});
}
}
});
};
</script>
</head> <body>
<div id="app">
<input v-model="msg" type="text" value=""/>
<input @click="add" type="button" value="添加"/>
<ul>
<transition-group
enter-active-class="animated rollIn"
leave-active-class="animated rollOut"
>
<li v-for="item,index in arr" :key="item">{{item}}<a @click="del(item)" href="javascript:;">删除</a></li>
</transition-group>
</ul> </div>
</body>
</html>

vue2-animate

cnpm i vue2-animate
vue-cli:引入外部文件

1、index.html页面安装传统的引入文件的方式进行引入

2、在入口文件main.js 通过import 直接导入

import "vue2-animate/dist/vue2-animate";


vuex

Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化

记住一句话:如果要修改state里面的值,只能通过mutaions进行修改!!!

https://vuex.vuejs.org/zh/guide/

https://github.com/vuejs/vuex

1、选安装

cnpm i -S vuex

2、导入

import Vuex from "vuex";

3、创建存储空间
let store = new Vuex.Store({
strict:true,严格模式
getters:{},
mutations:{},
actions:{},
modules:{}
});

每一个 Vuex 应用的核心就是 store(仓库)。“store”基本上就是一个容器,它包含着你的应用中大部分的状态 (state)。Vuex 和单纯的全局对象有以下两点不同:

Vuex 的状态存储是响应式的。当 Vue 组件从 store 中读取状态的时候,若 store 中的状态发生变化,那么相应的组件也会相应地得到高效更新。

你不能直接改变 store 中的状态。改变 store 中的状态的唯一途径就是显式地提交 (commit) mutation。这样使得我们可以方便地跟踪每一个状态的变化,从而让我们能够实现一些工具帮助我们更好地了解我们的应用

4、注入实例Vue
new Vue({
store
})

通信方式:

组件--->store

0、this.$store.state.count = xxx; 不推荐的 错误方式

1、this.$store.commit("mutation",value);

2、this.$store.dispatch("action",value);

store-->store

action--->mutation

ctx.commit("mutation",value);

ctx.dispatch("action",value);

action/mutation区别

mutation只能做同步操作不能做异步!

所有数据修改只能通过mutation进行,

action不能直接修改state值

getters:简单的认为就是获取数据的一个计算属性

使用的时候不需要带括号: this.$store.getters.方法名称

exp:

import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex); export default new Vuex.Store({
strict:true,
state:{
count:1,
},
getters:{
filterCount(state){
return state.count >= 20? "20":state.count;
}
},
mutations:{//只能做同步操作
plusMutation(state,payload){//value payload有效载荷
state.count++;
},
minusMutation(state,payload){//value payload有效载荷
state.count--;
}
},
actions:{//执行同步和异步操作
plusAction({commit,dispatch},payload){//ctx容器 payload有效载荷
commit("plusMutation");
},
minusAction({commit},payload){
commit("minusMutation");
}
}
});

模块:多人开发,命名冲突

1、模块之间的数据访问,是区分模块

this.$store.state.count

this.$store.state.modA.count

2、方法不区分模块

this.$store.commit("mutation",value);

如果要区分模块 需要加上命名空间

在子模块中添加 namespaced: true,

调用子模块的方法

this.$store.commit("modA/mutation",value);


功能函数

mapState/mapGetters/mapActions/mapMutations

... 解构赋值

store.vue
<template>
<div>
<input @click="minus" type="button" value="减"/><br />
{{count}}------{{filterCount}} <br />
<input @click="plus" type="button" value="加"/> </div>
</template> <script>
import {mapState,mapGetters,mapActions,mapMutations} from "vuex"; console.log("mapState:",mapState({count:"count"}));
console.log("mapGetters:",mapGetters({filterCount:"filterCount"}));
console.log("mapActions:",mapActions({minus:"minusAction"}));
console.log("mapMutations:",mapMutations({plus:"plusMutation"})); export default {
name: "Store",
data(){
return{ }
},
computed:{
...mapState({count:"count"}),
...mapGetters({filterCount:"filterCount"})
},
methods:{
...mapActions({minus:"minusAction"}),
...mapMutations({plus:"plusMutation"})
},
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped> </style>
store.js

import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex); export default new Vuex.Store({
strict:true,
state:{
count:1,
},
getters:{
filterCount(state){
return state.count >= 20? "20":state.count;
}
},
mutations:{//只能做同步操作
plusMutation(state,payload)st{//value payload有效载荷
state.count++;
},
minusMutation(state,payload){//value payload有效载荷
state.count--;
}
},
actions:{//执行同步和异步操作
plusAction({commit,dispatch},payload){//ctx容器 payload有效载荷
commit("plusMutation");
},
minusAction({commit},payload){
commit("minusMutation");
}
}
});
混入 (mixins)

mixins是一种分发 Vue 组件中可复用功能的非常灵活的方式。混入对象可以包含任意组件选项。当组件使用混入对象时,所有混入对象的选项将被混入该组件本身的选项。

<template>
<div>
<input @click="minus" type="button" value="减"/><br />
{{count}}------{{filterCount}} <br />
<input @click="plus" type="button" value="加"/> </div>
</template> <script>
import {mapState,mapGetters,mapActions,mapMutations} from "vuex"; console.log("mapState:",mapState({count:"count"}));
console.log("mapGetters:",mapGetters({filterCount:"filterCount"}));
console.log("mapActions:",mapActions({minus:"minusAction"}));
console.log("mapMutations:",mapMutations({plus:"plusMutation"})); let stateMixi = {
computed:mapState({count:"count"})
};
let gettersMixi = {
computed:mapGetters({filterCount:"filterCount"})
};
let actionsMixi = {
methods:mapActions({minus:"minusAction"})
};
let mutationsMixi = {
methods:mapMutations({plus:"plusMutation"})
}; export default {
name: "Store",
data(){
return{ }
},
mixins: [stateMixi,gettersMixi,actionsMixi,mutationsMixi]
// computed:mapGetters({filterCount:"filterCount"}),
// methods:mapMutations({plus:"plusMutation"}), // computed:{
// // count(){
// // return this.$store.state.count;
// // },
// // filterCount(){
// // return this.$store.getters.filterCount;
// // }
// },
// methods:{
// plus(){
// //mutation
// this.$store.commit("plusMutation");
// },
// minus(){
// //action
// this.$store.dispatch("minusAction");
// },
// }
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped> </style>

15.vue动画& vuex的更多相关文章

  1. 基于vue2.0打造移动商城页面实践 vue实现商城购物车功能 基于Vue、Vuex、Vue-router实现的购物商城(原生切换动画)效果

    基于vue2.0打造移动商城页面实践 地址:https://www.jianshu.com/p/2129bc4d40e9 vue实现商城购物车功能 地址:http://www.jb51.net/art ...

  2. webpack4 + vue + vue-router + vuex

    ps: 所有案例使用的 node 及 npm 版本如下 node版本: v8.4.0 npm: 5.3.0 下一个案例默认是接着上一个继续写的 建议先熟悉以下文档 vue vue-router vue ...

  3. 【09】Vue 之 Vuex 数据通信

    9.1. 引言 Vue组件化做的确实非常彻底,它独有的vue单文件组件也是做的非常有特色.组件化的同时带来的是:组件之间的数据共享和通信的难题. 尤其Vue组件设计的就是,父组件通过子组件的prop进 ...

  4. Vue 2.0 + Vue Router + Vuex

    用 Vue.js 2.x 与相配套的 Vue Router.Vuex 搭建了一个最基本的后台管理系统的骨架. 当然先要安装 node.js(包括了 npm).vue-cli 项目结构如图所示: ass ...

  5. Vue之Vuex

    一.什么是vuex Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.简单来说就是一个数据统一 ...

  6. vue动画的用法

    vue动画 在vue.js中有两种写动画的方法,第一种就是像js里一样,用原生代码来实现,第二种则是使用animate.css的动画类文件,这个动画类和bootstrap.css文件类似,直接调用类就 ...

  7. requirejs、vue、vuex、vue-route的结合使用,您认为可行吗?

    在五一节之前和一网友讨论前端技术时,对方提到vue.vue-route如果配合requirejs应用.当时的我没有想得很明白,也没能这位网友一个准确的回复,但我许诺于他五一研究后给他一个回复.本是一天 ...

  8. vue动画及其原理

    1,vue动画的实现原理,主要是通过在不同时期给需要动画的dom元素加上css动画样式 我们以显示和隐藏动画为例 a, 需要动画的dom元素 b,点击时vue控制往vue中加的样式 2,  我们以两张 ...

  9. Vue中Vuex的详解与使用(简洁易懂的入门小实例)

    怎么安装 Vuex 我就不介绍了,官网上有 就是 npm install xxx 之类的.(其实就是懒~~~哈哈) 那么现在就开始正文部分了 众所周知 Vuex 是什么呢?是用来干嘛的呢? Vuex ...

随机推荐

  1. Unity3D性能优化最佳实践(四)资源审查

    Asset auditing - 资源审查 许多项目发生效能问题的真正原因只是由于人员操作不当或是试东试西,而不小心改到导入设定影响到导入的资源.(例如最近的gitlab惨案) 对于较大规模的项目,最 ...

  2. nvidia-docker2配置与NVIDIA驱动安装

    要运行高版本的GPU版TensorFlow,需要更新宿主机的显卡驱动(本文以NVIDIA390为例) 一.更新驱动 禁用nouveau驱动: 添加/etc/modprobe.d/blacklist.c ...

  3. SSH方式连接Git服务器需要注意的地方

    如何安装Git?这个我这里就不再多说了,想要了解的可以自行百度,以下文字是基于本地Git安装OK,且Git服务器可用的情况下,我的Git是GitLab 接下来开始操作 1:首先在本地生成私钥和公钥,这 ...

  4. Django 数据表更改

    Django 数据表更改 « Django 开发内容管理系统(第四天) Django 后台 » 我们设计数据库的时候,早期设计完后,后期会发现不完善,要对数据表进行更改,这时候就要用到本节的知识. D ...

  5. window系统命令行设置proxy----Setting a proxy for Windows using the command-line

    设置代理, bypass-list的参数是不走代理地址: netsh winhttp set proxy proxy-server="socks=localhost:9090" b ...

  6. MVC Json方法里的一个坑

    MVC Controller类下面有这样一个方法 // // Summary: // Creates a System.Web.Mvc.JsonResult object that serialize ...

  7. CentOS 安装Nginx1.14.0

    原文地址:http://www.cnblogs.com/ascd-eg/p/9275441.html 一.安装所需环境   1.gcc 安装         yum install gcc-c++   ...

  8. Effective Java 第三版——76. 争取保持失败原子性

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  9. webview调起浏览器

    调起浏览器 url = "intent://" + url +"#Intent;scheme=http;action=android.intent.action.VIEW ...

  10. Vue父子组件双向数据绑定

    [本文出自天外归云的博客园] 简介 Vue版本:2.9.6 Element版本:2.4.8 问题描述:子组件对Element中el-select进行封装,父组件中把选中的值selected和所有选项o ...