citys.vue 1.7 KB

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