提交 c27b5929 编写于 作者: M maguohua

updata

上级 3dc1b6d7
import {baseUrl} from './env'
export default (type = 'GET', url = '', data = {}) => {
return new Promise((resolve, reject) => { //定义一个promise
return new Promise((resolve, reject) => { //返回一个promise
type = type.toUpperCase();
url = baseUrl + url
let requestObj = {
......
......@@ -2,57 +2,15 @@ import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router/router'
import store from './store/'
import ajax from './config/ajax'
import fetch from './config/fetch'
import {routerMode} from './config/env'
import './style/common.scss'
import './config/rem'
import {cityGuess} from './service/getData'
cityGuess().then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})
// fetch('GET', '/shopping/restaurants',{
// latitude: 31.16407,
// longitude: 121.38876,
// offset: 0,
// limit: 20,
// 'extras[]': 'activities',
// })
// ajax('get', '/v2/index_entry', {
// geohash: 'wtw3630xg5e',
// group_type: 1,
// 'flags[]': 'F',
// })
// var obj = {
// mobile: '13681711254',
// scene: 'login',
// type: 'sms',
// }
// fetch('POST', '/v4/mobile/verify_code/send', obj)
// var loginObj = {
// code:567052,
// mobile: '13681711254',
// validate_token: '6a869f38c6d0a0bb5b023b35c5e35ceef8d710c1502369d56709b1632df830f8'
// }
// fetch('POST', '/v1/login/app_mobile', loginObj)
Vue.use(VueRouter)
const router = new VueRouter({
routes,
mode: routerMode,
routes
strict: process.env.NODE_ENV !== 'production'
})
new Vue({
......
......@@ -15,9 +15,18 @@
</template>
<script>
import {cityGuess} from '../../service/getData'
export default {
created(){
// cityGuess().then(res => {
// console.log(res)
// }).catch(err => {
// console.log(err)
// })
this.$store.dispatch('getData')
}
}
</script>
......
import App from '../App'
const home = r => require.ensure([], () => r(require('../page/home')), 'home')
const city = r => require.ensure([], () => r(require('../page/city')), 'city')
const msite = r => require.ensure([], () => r(require('../page/msite')), 'msite')
......
import setPromise from './setPromise'
import fetch from '../config/fetch'
/**
* 获取首页默认地址
*/
const cityGuess = (type = 'GET', url = '/v1/cities', data = {type: 'guess'}) => {
return setPromise(type, url, data)
}
const cityGuess = () => fetch('GET', '/v1/cities', {type: 'guess'})
export {cityGuess}
\ No newline at end of file
import fetch from '../config/fetch'
export default (type, url, data) => {
export default (type = 'GET', url = '', data = {}) => {
return new Promise((resolve, reject) => {
fetch(type, url, data).then(res => {
resolve(res)
......
import ajax from '../config/ajax'
import {cityGuess} from '../service/getData'
import { GET_DATA } from './mutation-types.js'
export default {
addNum({ commit, state }, id) {
commit('REMBER_ANSWER', { id })
if (state.itemNum < state.itemDetail.length) {
commit('ADD_ITEMNUM', {
num: 1
})
}
},
getData({ commit, state }) {
ajax('GET', 'http://operating-activities.putao.com/happyfriday?active_topic_id=4').
then(res => {
commit('GET_DATA', {
res
})
cityGuess().then(res => {
commit(GET_DATA, {data: res})
})
},
initializeData({ commit }) {
commit('INITIALIZE_DATA')
}
}
\ No newline at end of file
export default {
}
\ No newline at end of file
......@@ -2,17 +2,21 @@ import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './action'
import ajax from '../config/ajax'
import getters from './getters'
import checkout from './modules/checkout'
Vue.use(Vuex)
const state = {
test1: null
}
export default new Vuex.Store({
state,
getters,
actions,
mutations
mutations,
modules: {
checkout,
}
})
\ No newline at end of file
import { GET_DATA2 } from '../../mutation-types'
import { cityGuess } from '../../../service/getData'
const state = {
test2: null
}
const getters = {
}
const mutations = {
[GET_DATA2] (state, { data }) {
console.log(data)
state.test2 = data
},
}
const actions = {
getData2({ commit, state }) {
cityGuess().then(res => {
commit(GET_DATA2, {data: res})
})
},
}
export default {
state,
getters,
mutations,
actions
}
\ No newline at end of file
export const GET_DATA = 'GET_DATA'
export const GET_DATA2 = 'GET_DATA2'
\ No newline at end of file
const GET_DATA = 'GET_DATA'
const ADD_ITEMNUM = 'ADD_ITEMNUM'
const REMBER_ANSWER = 'REMBER_ANSWER'
const REMBER_TIME = 'REMBER_TIME'
const INITIALIZE_DATA = 'INITIALIZE_DATA'
const GET_USER_INFORM = 'GET_USER_INFORM'
import { GET_DATA } from './mutation-types.js'
export default {
[GET_DATA](state, payload) {
if (payload.res.httpStatusCode == 200) {
state.itemDetail = payload.res.topiclist;
}
},
[GET_USER_INFORM](state, payload) {
state.user_id = payload.res.users_id;
},
[ADD_ITEMNUM](state, payload) {
state.itemNum += payload.num;
},
[REMBER_ANSWER](state, payload) {
state.answerid[state.itemNum] = payload.id;
},
[REMBER_TIME](state) {
state.timer = setInterval(() => {
state.allTime++;
}, 1000)
},
[INITIALIZE_DATA](state) {
state.itemNum = 1;
state.allTime = 0;
[GET_DATA] (state, { data }) {
console.log(data)
state.test1 = data
},
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册