index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import axios from "axios"
  4. Vue.use(Vuex)
  5. // 创建一个新的 store 实例
  6. const store = new Vuex.Store({
  7. // 状态数据声明
  8. state () {
  9. return {
  10. phone :'',
  11. webSocketMsg:'1',
  12. Termsofinvitation:{},//商邀表格全局变量
  13. PaymentRequest:{},//日常付款全局变量
  14. }
  15. },
  16. // 在 mutations 内封装数据更新方法
  17. mutations: {
  18. SET_WS_MSG: (state, msg) =>{
  19. state.webSocketMsg = msg
  20. },
  21. setphone(state,phone){
  22. state.phone=phone
  23. }
  24. },
  25. actions:{
  26. vlogin(context,form){
  27. console.log(form)
  28. return new Promise((resolve,reject)=>{//Promise异步任务执行 抛出错误
  29. axios.post(//axios的基本操作
  30. "http://132.232.92.186:8888/api/login",
  31. `number=${form.number}&password=${form.password}`
  32. ).then(result=>{
  33. console.log(result)
  34. if(result.status>=200 && result.status<300){
  35. resolve();//抛出正确
  36. }else{
  37. reject(result.data);//抛出错误
  38. }
  39. })
  40. })
  41. }
  42. }
  43. });
  44. // 导出状态对象
  45. export default store