<header> <nav> <a href="#">home</a> <a href="#">page</a> </nav> </header>
scssjavascript
nav { a { color: red; header { color:green; } } }
css:css
.box { font-size: 12px; font-weight: bold; }
scss:html
.box { font: { size: 12px; weight: bold; } }
.clearfix{ &:before, &:after { content:""; display: table; } &:after { clear:both; overflow: hidden; } }
申明:vue
@mixin border-radius { -webkit-border-radius: 5px; border-radius: 5px; }
调用:java
button { @include border-radius; }
.btn { border: 1px solid #ccc; padding: 6px 10px; font-size: 14px; } .btn-primary { background-color: #f36; color: #fff; @extend .btn; }
容器默认存在两根轴:水平的主轴(main axis)和垂直的交叉轴(cross axis)。主轴的开始位置(与边框的交叉点)叫作main start,结束位置叫作main end;交叉轴的开始位置叫作cross start,结束位置叫作cross end。
项目默认沿主轴排列。单个项目占据的主轴空间叫作main size,占据的交叉轴空间叫作cross sizeios
核心概念:vuex应用的核心是store,里面包含大部分的state,vuex的状态存储是响应式的,state中的状态不能直接更改web
/*vueStore.js*/ import Vue from 'vue' import Vuex from 'vuex' import moduleA from './moduleA.js' Vue.use(Vuex); let state = { a1: 12, data: ['a','a','a','a','a'] }; let getters = { printData: state => { console.log(state.data); return state.data; } }; let mutations = { setData(state, data){ state.data = data; } }; let actions = { setData({ commit },n){ commit('setData', n); } }; export default new Vuex.Store({ strict: true, state, getters, mutations, actions, modules: { moduleA } });
/*moduleA.js*/ let state = { data: ['A', 'A',' A', 'A', 'A'] }; let getters = { printDataA: state => { return state.data; } }; let mutations = { setDataA(state, data) { state.data = data; } }; let actions = { setDataA({commit}, n) { commit('setDataA', n); } }; export default ({ strict: true,//严格模式 namespaced: true, state, getters, mutations, actions })
在根实例中注册store选项,该store就会注入到下面的全部组件,子组件经过this.$store能访问到vuex
computed: { count () { return this.$store.state.data //['a','a','a','a','a'] } }
getter相似于计算属性,它的返回值会根据它的依赖被缓存起来,只有当它它的依赖值发生改变才会从新计算,也能够接受其余get特然做为第二个参数axios
getter会暴露store。getter对象api
methods:{ getData(){ this.$store.getters.printData; //['a','a','a','a','a'] } }
经过方法访问
getters: { getTodoById: (state) => (id) => { return state.todos.find(todo => todo.id === id) } } store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false
vuex中更改store中的状态的惟一方法就是提交mutation,它接受state做为第一个参数,触发mutation的方法徐调用store.commit,咱们能够向store.commit转入额外的参数,即mutation的载荷(payload)
methods:{ send(){ this.$store.commit('setData', [0,0,0,0,0]); console.log(this.$store.state.data); //[0,0,0,0,0] }
mutation必须是同步函数;
action相似于mutation,不一样在于:
action接受一个与store实例具备相同方法和属性的context对象,context.commit来提交一个mutation、context.state、context.getters
Action 经过 store.dispatch 方法触发:
methods:{ send(){ this.$store.dispatch('setData', [0,0,0,0,0]); console.log(this.$store.state.data); //[0,0,0,0,0] } }
Vuex 容许咱们将 store 分割成模块(module)。每一个模块拥有本身的 state、mutation、action、getter、甚至是嵌套子模块——从上至下进行一样方式的分割
store.state.moduleA //moduleA的状态 store.commit('setDataA',[0,0,0,0,0]) //触发moduleA的mutation中的setDataA store.dispatch('setDataA',[0,0,0,0,0]) //moduleA actions store.getters.printDataA; //getter
命名空间
默认状况下模块内部的action、mutation、getter是注册在全局命名空间的,因此多个模块可以对同一mutation、action作出响应。添加namespaced: true的方式使其成为命名空间模块,它的全部 getter、action 及 mutation 都会自动根据模块注册的路径调整命名。
store.state.moduleA //moduleA的状态 store.commit('moduleA/setDataA',[0,0,0,0,0]) //触发moduleA的mutation中的setDataA store.dispatch('moduleA/setDataA',[0,0,0,0,0]) //moduleA actions store.getters['moduleA/printDataA']; //moduleA getter
axios(config);
axios(url[,config]);
axios({ method:"POST", url:'/user/a', data:{ msg: 'helloWorld' } });
axios.request(config);
axios.get(url[,config]);
axios.delete(url[,config]);
axios.head(url[,config]);
axios.post(url[,data[,config]]);
axios.put(url[,data[,config]])
axios.patch(url[,data[,config]])
axios.all(params)
axios.spread(callback) ; //callback要等到全部请求都完成才会执行
axios.create([config])
实例方法
axios#request(config) axios#get(url[,config]) axios#delete(url[,config]) axios#head(url[,config]) axios#post(url[,data[,config]]) axios#put(url[,data[,config]]) axios#patch(url[,data[,config]])
then/catch
方法以前对数据进行改动put/post/patch
/*search.js*/ import axios from 'axios'; export default function (keywords, type) { const require = new Promise((resolve, reject) => { axios.get('http://47.94.16.170:3000/search',{ params:{ keywords: keywords, type: type }, }).then((data)=> { resolve(data); }) }); return require; } /*调用*/ import search from '@/api/search'; let that = this; search(this.searchText, this.searchType).then(function (data) { that.content = data.result; })
axios.defaults.baseURL = 'http://api.exmple.com';
var instance = axios.create({ baseURL: 'https://api.example.com' }); instance.defaults.headers.common["Authorization"] = AUTH_TOKEN; instance.get('/longRequest',{ timeout: 5000 });
lib/defaults.js < 实例中的默认配置 < 请求中的默认配置
//添加一个请求拦截器 axios.interceptors.request.use(function(config){ //在请求发出以前进行一些操做 return config; },function(err){ //Do something with request error return Promise.reject(error); }); //添加一个响应拦截器 axios.interceptors.response.use(function(res){ //在这里对返回的数据进行处理 return res; },function(err){ //Do something with response error return Promise.reject(error); })