作者 张侠英

提交2

... ... @@ -14,7 +14,7 @@
"vant": "^2.8.2",
"vue": "^2.6.10",
"vue-router": "^3.0.3",
"vuex": "^3.0.1"
"vuex": "^3.4.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.5",
... ...
... ... @@ -32,20 +32,20 @@ export default {
},
methods: {
goFangDa () {
this.$router.push("/fangDa");
this.$router.push("/fangDa")
},
//获取数据
getData(){
getData() {
let that = this
this.$axios.post('/Index/shouye',{
this.$axios.post('api/Index/shouye', {
city: ''
}).then(res=>{
// this.msg=res.data.msg;
that.arr = res.data.data;
}).then(res => {
// this.msg=res.data.msg
that.arr = res.data
console.log(res)
}).catch(e=>{
console.log(e);
}).catch(e => {
console.log(e)
})
}
... ...
... ... @@ -13,20 +13,24 @@ import Vant from 'vant'
import 'vant/lib/index.css'
Vue.config.productionTip = false
Axios.defaults.baseURL = '/api/'
Vue.prototype.$axios=Axios
Vue.prototype.$axios = Axios
// let getCookie=funtion(cookie){
// let reg = /csrftoken=([\w]+)[;]?/g
// return reg.exec(cookie)[1]
// }
//添加请求拦截器
//添加请求拦截器,在请求头中加token
Axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
//
config=>{
if(localStorage.getItem('Authorization')){
config.headers.Authorization=localstorage.getItem('Authorization');
}
}
  return config
}, function (error) {
  // 对请求错误做些什么
return Promise.reject(error)
return Promise.reject(error)
});
//添加响应拦截器
Axios.interceptors.response.use(function(response){
... ...
... ... @@ -139,5 +139,20 @@ export default new Router({
component: () => import('./views/XiangQing.vue')
}
]
})
],
//使用 router.beforeEach注册一个全局前置守卫,判断用户是否登录
// router.beforeEach((to,from,next)=>{
// if(to.path === '/login'){
// next();
// }else{
// let token=localStorage.getItem('Authorization');
// if(token ==='null'|| token === ''){
// next('/login');
// }else{
// next();
// }
// }
// })
});
... ...
import Vue from 'vue'
import Vuex from 'vuex'
import Vuex from 'vuex';
Vue.use(Vuex)
Vue.use(Vuex);
export default new Vuex.Store({
state: {
//存储token
Authorization:localStorage.getItem('Authorization') ? localStorage.getItem('Authorization' ) : ''
},
mutations: {
//修改token,并将token存入localStorage
changeLogin(state,user){
state.Authorization=user.Authorization;
localStorage.setItem('Authorization',user.Authorization);
}
},
actions: {
... ...
... ... @@ -22,44 +22,73 @@
</div>
</template>
<script>
<script>
import { mapMutations } from 'vuex';
export default {
name: 'home',
components: {
},
data() {
data () {
return {
loginForm: {
mobile:'',
password:''
mobile: '',
password: ''
}
}
},
mounted: function () {
this.$axios({
method: 'post',
url: '/login/index'
}).then(r => {
console.log(111)
}).catch(e => {
console.log(2222)
})
},
methods: {
back1 () {
this.$router.go(-1);
this.$router.go(-1)
},
goForget () {
this.$router.push('/forget');
this.$router.push('/forget')
},
goRegister () {
this.$router.push('/register');
this.$router.push('/register')
},
goLoginSuccessful (){
let that=this;
if(this.loginForm.mebile === '' || this.loginForm.passeord === ''){
alert('手机号和密码不能为空');
}
this.$router.push('/loginSuccessful');
}
...mapMutations(['changeLogin']),
goLoginSuccessful () {
let _this = this
if (this.loginForm.mebile === '' || this.loginForm.passeord === '') {
alert('手机号和密码不能为空')
} else {
_this.$axios({
method: 'post',
url: '/Login/login',
data: _this.loginForm
}).then(res => {
console.log('----')
console.log(res.data)
_this.userToken = 'token' + res.data.data.body.token
_this.changeLogin({ Authorization: _this.userToken })
localStorage.removeItem('Authorization')
_this.$router.push('/loginSuccessful')
alert('登录成功')
}).catch(error => {
alert('手机号或密码错误')
console.log(error)
})
}
}
}
}
</script>
<style lang="scss" scoped>
... ...
... ... @@ -9,7 +9,7 @@
</div>
<div class="nav">
<van-dropdown-menu active-color="#11A7FC">
<van-dropdown-item :value="value1" active-color="#11A7FC" :options="option1" title="性别" @change="changeDevelop"/>
<van-dropdown-item :value="value1" active-color="#11A7FC" :options="option1" title="性别" />
<van-dropdown-item :value="value2" :options="option2" title="年龄" style="width:15%" ref="item"> <van-button type="info" block bind:click="onConfirm">
确定
</van-button></van-dropdown-item>
... ... @@ -85,15 +85,7 @@ export default {
}
},
methods: {
changeDevelop (i) {
this.title= this.developList[i-1].text
},
onConfirm() {
this.$refs.item.toggle();
},
onConfirm1() {
this.selectComponent('#item').toggle();
}
}
}
</script>
... ...
module.exports = {
devServer: {
open: true,
host: 'localhost',
port: 8081,
https: false,
hotOnly: false,
// http 代理配置
proxy: {
'/api': {
target: 'http://hunlianh5.t.brotop.cn',
... ...