午夜勾魂曲-午夜福利自怕-午夜福利在线观看6080-午夜福利院电影-国产精品毛片AV久久97-国产精品麻豆高潮刺激A片

關于Vuex的全家桶狀態管理(一)

2018-5-29    seo達人

如果您想訂閱本博客內容,每天自動發到您的郵箱中, 請點這里

1:安裝

 npm install vuex --save
    
  • 1

2: 在main.js 主入口js里面引用store.js

import Vue from 'vue' import App from './App' import router from './router' import store from './vuex/store' //引用store.js Vue.config.productionTip = false //阻止在啟動時生成生產提示 //vue實例 new Vue({
 el: '#app',
 router,
 store, //把store掛在到vue的實例下面 template: '<App/>',
 components: { App }
})
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

3:在store.js里引用Vuex

import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) //注冊Vuex // 定義常量  如果訪問他的話,就叫訪問狀態對象 const state = {
  count: 1 } // mutations用來改變store狀態, 如果訪問他的話,就叫訪問觸發狀態 const mutations = { //這里面的方法是用 this.$store.commit('jia') 來觸發 jia(state){
    state.count ++
  },
  jian(state){
    state.count --
  },
} //暴露到外面,讓其他地方的引用 export default new Vuex.Store({
  state,
  mutations
})
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

4:在vue組件中使用

使用$store.commit(‘jia’)區觸發mutations下面的加減方法

<template> <p class="hello"> <h1>Hello Vuex</h1> <h5>{{$store.state.count}}</h5> <p> <button @click="$store.commit('jia')">+</button> <button @click="$store.commit('jian')">-</button> </p> </p> </template> <!-- 加上scoped是css只在這個組件里面生效,為了不影響全局樣式 --> <style scoped> h5{ font-size: 20px; color: red; } </style>
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

這里寫圖片描述

5:state訪問狀態對象

使用computed計算

<template> <p class="hello"> <h1>Hello Vuex</h1> <h5>{{count}}</h5> <p> <button @click="$store.commit('jia')">+</button> <button @click="$store.commit('jian')">-</button> </p> </p> </template> <script> import {mapState} from 'vuex' export default{
  name:'hello', //寫上name的作用是,如果你頁面報錯了,他會提示你是那個頁面報的錯,很實用 // 方法一 // computed: { //  count(){ //   return this.$store.state.count + 6 //  } // } // 方法二 需要引入外部 mapState computed:mapState({
   count:state => state.count + 10 }) // ECMA5用法 // computed:mapState({ //  count:function(state){ //   return state.count //  } // }) //方法三 // computed: mapState([ //  'count' // ]) } </script>
藍藍設計m.gerard.com.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 平面設計服務

日歷

鏈接

個人資料

藍藍設計的小編 http://m.gerard.com.cn

存檔

主站蜘蛛池模板: 老师扒开尿口男生摸尿口 | 伊人国产视频 | 国产精品无码AV天天爽人妻蜜桃 | 寂寞夜晚视频在线观看 | 60老妇性xxxxhd | 精子网久久国产精品 | 三级黄毛片 | 99久久全国免费久久爱 | 国产亚洲精品久久久久久久 | 一本色道久久综合一区 | 亚洲中文字幕永久在线 | 扒开双腿疯进出爽爽爽动态图 | 淫品色影院| 成人免费毛片观看 | 日本久久黄色 | 亚洲 欧美 综合 高清 在线 | 亚洲第一综合天堂另类专 | japansemature护士| 国产乱码免费卡1卡二卡3卡四卡 | 亚洲色图在线观看视频 | 精品久久久久久久国产潘金莲 | 成年人视频在线观看免费 | 教室眠催白丝美女校花 | 精品极品三大极久久久久 | 精品99久久久久成人网站 | 亚洲一区精品伊人久久伊人 | 国产精品久久久久久久久久免费 | china年轻小帅脸直播飞机 | 午夜影院视费x看 | 久久精品天天中文字幕 | 亚洲男人97色综合久久久 | 国产成久久免费精品AV片天堂 | 空姐被黑人 苏晓曼 | 丰满女友bd高清在线观看 | [高清无码] 波多野结衣| 秋霞鲁丝片Av无码 | 天堂网久久 | 最新国自产拍天天更新 | 果冻传媒在线观看网站 | 久久精品亚洲视频 | 久久中文字幕综合不卡一二区 |