当前位置: 首页 > news >正文

Vue指令

创建项目:

vue init webpack 项目名称

element-ui

npm i element-ui -s

axios

npm i axios@1.1.3 -S

vuex

npm i vuex@3.6.2 -S

vuex持久化

npm i -S vuex-persistedstate@4.1.0

代理模版

   proxyTable: {'/api': {target: 'http://localhost:8081/',changeOrigin: true,pathRewrite: {'^/api': '/ktnews/api'}},'/static': {target: 'http://localhost:8081/',changeOrigin: true,pathRewrite: {'^/static': '/ktnews/static'}}},

stroe index.js 

import Vue from 'vue'
import Vuex from "vuex";
import UserStore from "./modules/user";
import VuePersistedStatePlugin from 'vuex-persistedstate';Vue.use(Vuex)const store = new Vuex.Store({plugins: [VuePersistedStatePlugin({storage: window.localStorage,reducer: (state) => {return {UserStore: state.UserStore}}})],state: {//根数据,可以直接使用this.$store.state.count访问count: 0},modules: {UserStore}
})export default store;
//用户未登录的默认数据
const defaultUserInfo={nickname:'未登录',username:'未登录',avatar:'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
}
//用户登录的数据
const state={userInfo:defaultUserInfo,//先使用默认数据isLogin:false
}
//控制信息修改的方法
const mutations={login(state,userInfo){//登录console.log('登录:',userInfo)state.userInfo=userInfo;state.isLogin=true;},logout(state){//退出登录console.log('退出登录')state.userInfo=defaultUserInfo;state.isLogin=false;}
}
export default {state,mutations,
}

main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from "axios";
import Store from "./store";Vue.config.productionTip = false
Vue.prototype.$axios = axios;Vue.prototype.$store = Store;
Vue.use(ElementUI);/* eslint-disable no-new */
new Vue({el: '#app',router,store: Store,components: {App},template: '<App/>'
})

http://www.lryc.cn/news/503046.html

相关文章:

  • 数据保护策略:如何保障重要信息的安全
  • Chrome webdriver下载-避坑
  • 递归求最大公约数
  • 关于在浏览器里面获取手机方向的事件
  • STM32 出租车计价器系统设计(一) 江科大源码改写
  • eclipse rcp-创建rcp-创建target
  • 微信小程序--创建一个日历组件
  • 质量问题分析与改进常见方法
  • 质数的和与积
  • 数据结构 (35)分配类排序
  • Cesium隐藏默认控件
  • Spark SQL 执行计划解析源码分析
  • rabbitMq举例
  • 奇怪的知识又增加了:ESP32下的Lisp编程=>ULisp--Lisp for microcontrollers
  • 渗透测试之信息收集
  • 基本分页存储管理
  • SQLServer到MySQL的数据高效迁移方案分享
  • 软考:工作后再考的性价比分析
  • shell编程(完结)
  • UNIX数据恢复—UNIX系统常见故障问题和数据恢复方案
  • adb连接逍遥安卓模拟器失败的问题解决方案
  • 【昇腾】NPU ID:物理ID、逻辑ID、芯片映射关系
  • Three.js曲线篇 8.管道漫游
  • scala基础_数据类型概览
  • 【LeetCode刷题之路】622.设计循环队列
  • 暂停一下,给Next.js项目配置一下ESLint(Next+tailwind项目)
  • Windows系统磁盘与分区之详解(Detailed Explanation of Windows System Disks and Partitions)
  • 顺序表的使用,对数据的增删改查
  • XDMA与FPGA:高效数据传输的艺术
  • #思科模拟器通过服务配置保障无线网络安全Radius