ionic怎么用js控制配置状态机

JavaScript014

ionic怎么用js控制配置状态机,第1张

(1) 看一遍ionic的文档

Ionic 是一个用HTML, CSS 跟JS 开发的一个用于移动设备的web app 开发框架,采用 Sass与AngularJS 开发。

(2) 看一遍phonegap的文档;目前phonegap又取名为cordova;有些常用的命令总结如下:

项目例子:

ionic:

Create hybrid mobile apps with the web technologies you love.

Free and open source, Ionic offers a library of mobile-optimized HTML,

CSS and JS components, gestures, and tools for building highly interactive apps.

Built with Sass and optimized for AngularJS.

index.js

import service from '../service.js'

import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({

  state: {

    /**

     * 是否需要强制登录

     */

    forcedLogin: true,

    hasLogin: false,

    userName: "",

msg: {}

  },

  mutations: {

    login(state, userName) {

      state.userName = userName || '新用户'

      state.hasLogin = true

    },

    logout(state) {

      state.userName = ""

      state.hasLogin = false

service.removeUser()

    },

setmsg(state, msg) {

state.msg = msg

}

  }

})

export default store

———————————————————————————————————————————————————————————————

引入:import {

             mapState,

             mapMutations

          } from 'vuex'

设置值:

              methods: {

                    ...mapMutations(['login', 'setmsg']),

              }

              let userMsg = {

                       user_grade: data.data.user_grade,

                       discount_rate: data.data.discount_rate

              }

  that.setmsg(userMsg)

获取值:

            computed:{

                ...mapState(['forcedLogin', 'hasLogin', 'userName','msg']),

            }

            this.msg(就可以出来了)