<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); })