const result = await reqAddress(geohash)
// 提交一个mutation
if (result.code === 0) {
const address = result.data
commit(RECEIVE_ADDRESS, {address})
}
},
// 异步获取食品分类列表
async getCategorys({commit}) {
// 发送异步ajax请求
const result = await reqFoodCategorys()
// 提交一个mutation
if (result.code === 0) {
const categorys = result.data
commit(RECEIVE_CATEGORYS, {categorys})
}
},
// 异步获取商家列表
async getShops({commit, state}) {
// 发送异步ajax请求
const {longitude, latitude} = state
const result = await reqShops(longitude, latitude)
// 提交一个mutation
if (result.code === 0) {
const shops = result.data
commit(RECEIVE_SHOPS, {shops})
}
},
// 同步记录用户信息
recordUser({commit}, userInfo) {
commit(RECEIVE_USER_INFO, {userInfo})
},
// 异步获取用户信息
async getUserInfo({commit}) {
const result = await reqUserInfo()
if (result.code === 0) {
const userInfo = result.data
commit(RECEIVE_USER_INFO, {userInfo})
}
},
// 异步登出
async logout({commit}) {
const result = await reqLogout()
if (result.code === 0) {
commit(RESET_USER_INFO)
}
},
// 异步获取商家信息
async getShopInfo({commit}) {
const result = await reqShopInfo()
if (result.code === 0) {
const info = result.data
commit(RECEIVE_INFO, {info})
}
},
// 异步获取商家评价列表
async getShopRatings({commit}, callback) {
const result = await reqShopRatings()
if (result.code === 0) {
const ratings = result.data
commit(RECEIVE_RATINGS, {ratings})
// 数据更新了, 通知一下组件
callback && callback()
}
},
// 异步获取商家商品列表
async getShopGoods({commit}, callback) {
const result = await reqShopGoods()
if (result.code === 0) {
const goods = result.data
commit(RECEIVE_GOODS, {goods})
// 数据更新了, 通知一下组件
callback && callback()
}
},
// 同步更新food中的count值
updateFoodCount({commit}, {isAdd, food}) {
if (isAdd) {
commit(INCREMENT_FOOD_COUNT, {food})
} else {
commit(DECREMENT_FOOD_COUNT, {food})
}
},
// 同步清空购物车
clearCart({commit}) {
commit(CLEAR_CART)
},
// 异步获取商家商品列表
async searchShops({commit, state}, keyword) {
const geohash = state.latitude + ‘,’ + state.longitude
const result = await reqSearchShop(geohash, keyword)
if (result.code === 0) {
const searchShops = result.data
commit(RECEIVE_SEARCH_SHOPS, {searchShops})
}
},
}
2.store/getters.js
/*
包含多个基于state的getter计算属性的对象
*/
export default {
totalCount (state) {
return state.cartFoods.reduce((preTotal, food) => preTotal + food.count , 0)
},
totalPrice (state) {
return state.cartFoods.reduce((preTotal, food) => preTotal + food.count*food.price , 0)
},
positiveSize (state) {
return state.ratings.reduce((preTotal, rating) => preTotal + (rating.rateType===0?1:0) , 0)
}
}
3.store/index.js
/*
vuex最核心的管理对象store
*/
import Vue from ‘vue’
import Vuex from ‘vuex’
import state from ‘./state’
import mutations from ‘./mutations’
import actions from ‘./actions’
import getters from ‘./getters’
Vue.use(Vuex)
export default new Vuex.Store({
state,
mutations,
actions,
getters
})
4.store/mutation-types.js
/*
包含n个mutation的type名称常量
*/
export const RECEIVE_ADDRESS = ‘receive_address’ // 接收地址
export const RECEIVE_CATEGORYS = ‘receive_categorys’ // 接收食品分类数组
export const RECEIVE_SHOPS = ‘receive_shops’ // 接收商家数组
export const RECEIVE_USER_INFO = ‘receive_user_info’ // 接收用户信息
export const RESET_USER_INFO = ‘reset_user_info’ // 重置用户信息
export const RECEIVE_GOODS = ‘receive_goods’ // 接收商品数组
export const RECEIVE_RATINGS = ‘receive_ratings’ // 接收商家评价数组
export const RECEIVE_INFO = ‘receive_info’ // 接收商家信息
export const INCREMENT_FOOD_COUNT = ‘increment_food_count’ // 增加food中的count
export const DECREMENT_FOOD_COUNT = ‘decrement_food_count’ // 减少food中的count
export const CLEAR_CART = ‘clear_cart’ // 清空购物车
export const RECEIVE_SEARCH_SHOPS = ‘receive_search_shops’ // 接收搜索的商家数组
5.store/mutations.js
/*
直接更新state的多个方法的对象
*/
import Vue from ‘vue’
import {
RECEIVE_ADDRESS,
RECEIVE_CATEGORYS,
RECEIVE_SHOPS,
RECEIVE_USER_INFO,
RESET_USER_INFO,
RECEIVE_INFO,
RECEIVE_RATINGS,
RECEIVE_GOODS,
INCREMENT_FOOD_COUNT,
DECREMENT_FOOD_COUNT,
CLEAR_CART,
RECEIVE_SEARCH_SHOPS
} from ‘./mutation-types’
export default {
[RECEIVE_ADDRESS] (state, {address}) {
state.address = address
},
[RECEIVE_CATEGORYS] (state, {categorys}) {
state.categorys = categorys
},
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**
[外链图片转存中…(img-iiE18mj1-1715674793637)]
[外链图片转存中…(img-5pH46sk8-1715674793638)]
[外链图片转存中…(img-6lGnm0XF-1715674793638)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!