citys.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <view>
  3. <city-select @cityClick="cityClick" :formatName="formatName" :obtainCitys="obtainCitys" :isSearch="true"
  4. ref="citys"></city-select>
  5. </view>
  6. </template>
  7. <script>
  8. import citys from './citys.js'
  9. // console.log(citys.length)
  10. import citySelect from '@/components/city-select/city-select.vue'
  11. export default {
  12. data() {
  13. return {
  14. //需要构建索引参数的名称(注意:传递的对象里面必须要有这个名称的参数)
  15. formatName: 'title',
  16. //当前城市
  17. activeCity: {},
  18. //热门城市
  19. hotCity: [],
  20. //显示的城市数据
  21. obtainCitys: [],
  22. }
  23. },
  24. components: {
  25. citySelect
  26. },
  27. onLoad(e) {
  28. //动态更新数据
  29. setTimeout(() => {
  30. //修改数据格式
  31. this.formatName = 'cityName'
  32. //修改当前城市
  33. // this.activeCity = {
  34. // cityName: '南京',
  35. // cityCode: 110100
  36. // }
  37. //修改热门城市
  38. // this.hotCity = [
  39. // {
  40. // cityName: '南京',
  41. // cityCode: 110100
  42. // },
  43. // {
  44. // cityName: '北京',
  45. // cityCode: 110102
  46. // }
  47. // ]
  48. //修改构建索引数据
  49. this.obtainCitys = citys
  50. }, 100)
  51. },
  52. methods: {
  53. cityClick(item) {
  54. uni.showToast({
  55. icon: 'none',
  56. title: '修改成功',
  57. mask: true
  58. })
  59. uni.setStorageSync('city', item.cityName)
  60. setTimeout(function() {
  61. // uni.navigateBack()
  62. let pages = getCurrentPages(); // 当前页面
  63. let beforePage = pages[pages.length - 2]; // 上一页
  64. console.log(beforePage)
  65. uni.navigateBack({
  66. success: function() {
  67. beforePage.onShow(); // 执行上一页的onShow方法
  68. }
  69. });
  70. }, 1000)
  71. }
  72. }
  73. }
  74. </script>
  75. <style></style>