首页 技术 正文
技术 2022年11月15日
0 收藏 726 点赞 3,597 浏览 1845 个字

# vue项目(用webpack构建)的前提是已安装了node.js,vue,vue-cli,webpack

# 主要命令
构建:vue init webpack 项目名(纯英文,且不可驼峰)
运行:npm run dev
打包:npm run build(需要修改配置信息)

# element-ui
## 安装:npm i element-ui -S
## 引用:在main.js中
import ElementUI from ‘element-ui’;
import ‘element-ui/lib/theme-chalk/index.css’;
Vue.use(ElementUI);
## 按需引入:
## 安装 babel-plugin-component
npm install babel-plugin-component -D
## .babelrc 修改为
{
“presets”: [[“es2015”, { “modules”: false }]],
“plugins”: [
[
“component”,
{
“libraryName”: “element-ui”,
“styleLibraryName”: “theme-chalk”
}
]
]
}
## 使用
import { Button, Select } from ‘element-ui’
Vue.component(Button.name, Button);
Vue.component(Select.name, Select);

# axios
## 安装
npm install axios
## 使用 main.js里
import axios from ‘axios’
Vue.prototype.$axios = axios
## 调用
this.$axios.(略)

# vuex
## 安装
npm install vuex –save
## main.js里
import Vuex from ‘vuex’
Vue.use(Vuex)
## 使用
参考腾讯视频vue教程
mutations与actions 如果是静态的全部变量用mutations即可,如果需要从接口获取,则需用actions(未测试)
## 获取变量
this.$store.state.变量名
## 修改变量
this.$store.commit(‘方法名’)(可带参数 mutations情况下)
his.$store.dispatch(‘方法名’) (可带参数 actions情况下)

# 激活状态 路由配置里
linkActiveClass:’is-active’

# 路由跳转
this.$router.push({name:’master’,params:{id:’参数’}});
name和params搭配,刷新的话,参数会消失
this.$router.push({path:’/master’,query:{id:’参数’}});
path和query搭配,刷新页面的话,url中的参数不会丢失,query中的参数成了url中的一部分

<!– 字符串 –>
<router-link to=”home”>Home</router-link>
<!– 渲染结果 –>
<a href=”home”>Home</a>
<!– 使用 v-bind 的 JS 表达式 –>
<router-link v-bind:to=”‘home'”>Home</router-link>
<!– 不写 v-bind 也可以,就像绑定别的属性一样 –>
<router-link :to=”‘home'”>Home</router-link>
<!– 同上 –>
<router-link :to=”{ path: ‘home’ }”>Home</router-link>
<!– 命名的路由 –>
<router-link :to=”{ name: ‘user’, params: { userId: 123 }}”>User</router-link>
<!– 带查询参数,下面的结果为 /register?plan=private –>
<router-link :to=”{ path: ‘register’, query: { plan: ‘private’ }}”>Register</router-link>

#路由获取参数
this.$route.query.参数名
this.$route.params.参数名
watch:{
‘$route'(to,from){

}
}

# 路由钩子
全局
router.beforeEach((to, from, next) => {
next()
})
局部
beforeRouteEnter:(to,from,next)=>{
return next()
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,581
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918