You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.1 KiB

1 year ago
<template>
<view>
<city-select
@cityClick="cityClick"
1 year ago
formatName="cityName"
1 year ago
:activeCity="activeCity"
:hotCity="hotCity"
:obtainCitys="obtainCitys"
:isSearch="true"
1 year ago
:is-refresh="true"
1 year ago
ref="citys"
1 year ago
@refreshLocation="refreshLocation"
1 year ago
></city-select>
</view>
</template>
<script>
import citys from '@/component/CitySelect/citys.js'
import CitySelect from "@/component/CitySelect/city-select.vue"
export default {
components: {
CitySelect
},
data() {
return {
//需要构建索引参数的名称(注意:传递的对象里面必须要有这个名称的参数)
//当前城市
1 year ago
activeCity: {},
1 year ago
//热门城市
hotCity: [
{
id: 0,
title: '南京市'
},
{
id: 1,
title: '南京市'
}
],
//显示的城市数据
1 year ago
obtainCitys: []
1 year ago
};
},
1 year ago
watch: {
vuex_location: {
handler:function(newVal, oldVal) {
this.activeCity = {
cityName: newVal.city,
cityCode: newVal.cityCode
}
},
deep: true,
immediate: true
}
},
mounted() {
this.$store.dispatch('getLocation')
},
1 year ago
onLoad () {
//动态更新数据
setTimeout(() => {
//修改需要构建索引参数的名称
this.formatName = 'cityName'
//修改当前城市
this.activeCity = {
1 year ago
cityName: this.vuex_location.city,
cityCode: this.vuex_location.cityCode
1 year ago
}
//修改热门城市
this.hotCity = [
{
cityName: '南京',
cityCode: 110100
},
{
cityName: '北京',
cityCode: 110102
}
]
//修改构建索引数据
this.obtainCitys = citys
1 year ago
}, 0)
1 year ago
},
methods: {
1 year ago
refreshLocation() {
this.$store.dispatch('getLocation')
},
1 year ago
cityClick(item) {
1 year ago
this.$store.commit('SET_CITY',{
cityName: item.cityName,
cityCode: item.cityCode
1 year ago
})
}
}
}
</script>
<style lang="scss">
</style>