|
@@ -9,4 +9,47 @@ get 方法 一般用于获取数据信息
|
|
|
post 方法 进行数据的传送 安全
|
|
|
put
|
|
|
delete
|
|
|
-...
|
|
|
+...
|
|
|
+
|
|
|
+## Vuex
|
|
|
+
|
|
|
+1.安装vuex
|
|
|
+npm install vuex
|
|
|
+yarn add vuex
|
|
|
+2.在main.js中将状态管理库进行引入
|
|
|
+
|
|
|
+
|
|
|
+vuex:
|
|
|
+1.state 存放读取数据
|
|
|
+在state对象中定义数据
|
|
|
+在需要使用的地方
|
|
|
+this.$store.state.xxx
|
|
|
+$store.state.xxx
|
|
|
+引入mapState对象 在computed中进行结构:...mapState(["xxx","xxx",...])
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+通过状态(数据源)集中管理驱动组件的变化。页面通过mapActions异步提交事件到actions。actions通过commit把对应参数同步提交到mutations。
|
|
|
+
|
|
|
+mutations会修改state中对于的值。 最后通过getters把对应值跑出去,在页面的计算属性中
|
|
|
+
|
|
|
+通过mapGetters来动态获取state中的值
|
|
|
+
|
|
|
+应用级的状态集中放在store中; 改变状态的方式是提交mutations,这是个同步的事物; 异步逻辑应该封装在actions中。
|
|
|
+
|
|
|
+state中保存着共有数据,数据是响应式的 getters可以对state进行计算操作,主要用来过滤一些数据,可以在多组件之间复用 mutations定义的方法动态修改state中的数据,通过commit提交方法,方法必须是同步的 actions将mutations里面处理数据的方法变成异步的,就是异步操作数据,通store.dispatch来分发actions,把异步的方法写在actions中,通过commit提交mutations,进行修改数据。
|
|
|
+
|
|
|
+modules:模块化vueX
|