Vuex页面跳转时数据传递

1.Vuex概念

Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式

这个状态自管理应用包含以下几个部分:

  • state,驱动应用的数据源;
  • view,以声明方式将 state 映射到视图;
  • actions,响应在 view 上的用户输入导致的状态变化。

以下是一个表示“单向数据流”理念的极简示意:

Vuex基本思想

2. 引入vuex

npm install vuex --save

3.在src/store文件下下创建一个store.js

import Vue from ‘vue‘
import Vuex from ‘vuex‘
Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        count: 0,
        apiDocInfo: {
            operationId: ""
        }
    },
    mutations: {
        //设置apiInfo的值
        setApiInfo(state, apiInfo) {
            state.apiDocInfo = apiInfo
        },
        increment: state => state.count++,
        decrement: state => state.count--,
    }
})

3.在 main.js中添加

//Vuex
import store from ‘./store/store‘  // 引入store 对象

new Vue({
  el: ‘#app‘,
  store,// 注入到根实例中
  router,
  components: {
    App
  },
  template: ‘<App/>‘
})

4.SetValue

   queryApiInfo(){
      let apiDocInfo={
        operationId:operationId
      };
     //直接设置
      // this.$store.state.apiDocInfo=apiDocInfo;
      //commit设置
      this.$store.commit(‘setApiInfo‘, apiDocInfo);// SET_ORDER为order值的设置方法的方法名

    },    

5.获取值

<template>
    <div >
           <span>{{count}}</span>
           <span>{{apiDocInfo}}</span>

    </div>
</template>
<script>
import {mapState} from ‘vuex‘;
export default {

  computed:mapState({
     count:state => state.count,
     apiDocInfo :state => state.apiDocInfo,
  }),
}
</script>

原文地址:https://www.cnblogs.com/feng123/p/9505404.html

时间: 2024-08-29 14:45:01

Vuex页面跳转时数据传递的相关文章

Android页面跳转和数据传递

Android应用开发-页面跳转和数据传递 Activity Android四大组件之一 可以理解为Android中的界面,每一个界面都是一个Activity Activity的使用必须在清单文件中进行配置 在清单文件中, 创建第二个Activity 需要在清单文件中为其配置一个activity标签 标签中如果带有这个子节点,则会在系统中多创建一个快捷图标 <intent-filter> <action android:name="android.intent.action.M

iOS页面跳转及数据传递

iOS页面跳转: 第一种 [self.navigationController pushViewController:subTableViewController  animated:YES]; //描述:通过 NSNavigationBar 进行跳转 [self.navigationController popViewControllerAnimated:YES]; //描述:在子视图返回到上级视图 第二种 UIViewController *control = [[UIViewControl

Android Day06四大组件之Activity多页面跳转和数据传递

1.什么是Activity   官方文档是这么说的:An Activity is an application component that provides a screen     with which users can interact in order to do something, such as dial the phone,     take a photo, send an email, or view a map. Each activity is given a wind

Android基础笔记(七)-页面跳转和数据传递

Activity简介 Activity的简单使用 Activity之间的跳转 意图传递数据 创建Activity获取返回数据 如何调用系统发送短信的页面 如何发送短信 Activity简介 Activity是Android的四大组件之一,它用于展示界面.它提供一个屏幕,用户可以用来交互,可以通过setContentView(View)来显示指定的控件. 在一个android应用中,一个Activity通常就是一个单独的屏幕,它上面可以显示一些控件也可以监听并处理用户的事件做出响应.Activit

Android应用开发-页面跳转与数据传递(重制版)

Android四大组件:Activity,Service,Broadcast Receiver,Content Provider 创建Activity 定义Java类,继承Activity类 在清单文件中配置activity标签 activity标签下如果带有下面这部分代码,则会在系统中多创建一个快捷图标 <intent-filter> <action android:name="android.intent.action.MAIN" /> <catego

页面跳转与数据传递

#创建第二个Activity 需要在清单文件中为其配置一个activity标签 标签中如果带有这个子节点,则会在系统中多创建一个快捷图标 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter

第六天 页面跳转和数据传递

1.  横竖屏切换是时候 会调用 oncreate , onstart  , 重建 . 在清单中 activity 中添加    .重建为横竖屏 适配  加载不同的 布局文件. android:configChanges="keyboardHidden|orientation|screenSize"     就不会重建. 2 .显示启动 Intent intent = new Intent(); intent.setClass(this, second.class);  //启动本应用

JQueryMobile页面跳转参数的传递解决方案

在JQueryMobile开发手机端应用使用可能需要考虑相关的页面跳转带来的参数问题.因为JQueryMobile其实也是HTML5实践的结果.HTML5中有localStorage和sessionStorage使用.最好采用Storage实现比较简单易用. 例如在页面A跳转B页面,在A跳转前将跳转参数注入到localStorage中,在B页面初始化获取localStorage相关的页面参数.并做相应的处理同时在适当的页面清理页面参数. storage.js内容如下: Js代码   functi

Html页面间跳转之数据传递

1.页面数据传递需要引入一个js文件,代码 UrlParm = function() { // url参数 var data, index; (function init() { data = []; index = {}; var u = window.location.search.substr(1); if (u != '') { var parms = decodeURIComponent(u).split('&'); for (var i = 0, len = parms.length