铝交易,微信公众号
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.

77 lines
1.3 KiB

4 months ago
  1. <template>
  2. <view class="change-language">
  3. <uv-picker ref="picker"
  4. :columns="languageList"
  5. keyName="name"
  6. :itemHeight="70"
  7. @confirm="confirm"></uv-picker>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props : {
  13. url : {
  14. default : '/pages/index/index',
  15. type : String,
  16. }
  17. },
  18. data(){
  19. return {
  20. languageList: [
  21. [
  22. {
  23. name:'简体中文',
  24. key : "zh-Hans"
  25. },
  26. {
  27. name:'English',
  28. key : "en"
  29. },
  30. ]
  31. ],
  32. }
  33. },
  34. methods : {
  35. open() {
  36. this.$refs.picker.open();
  37. },
  38. confirm(e) {
  39. this.changeLanguage(e.value.pop())
  40. },
  41. //修改当前语言
  42. changeLanguage(res){
  43. //#ifdef H5
  44. this.$router.go(0); //刷新页面,不然validate.js不好国际化
  45. //#endif
  46. //#ifdef APP-PLUS
  47. uni.navigateTo({
  48. url: this.url // 要刷新的页面路径
  49. });
  50. //#endif
  51. if(!res.key){
  52. return
  53. }
  54. uni.setStorage({
  55. key: 'language',
  56. data: res.key
  57. })
  58. this.$i18n.locale = res.key
  59. uni.setLocale(res.key) //切换语言环境必须在this.$i18n.locale之后,否则app端会有意想不到的bug
  60. uni.$responseMessage = this.$t('responseMessage')
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .change-language{
  67. position: relative;
  68. z-index: 999999999;
  69. }
  70. </style>