config.ts 1.3 KB

1234567891011121314151617181920212223
  1. import { defineStore } from 'pinia';
  2. // defineStore 方法有两个参数,第一个参数是模块化名字(也就相当于身份证一样,不能重复)
  3. // 第二个参数是选项,对象里面有三个属性,相比于vuex 少了一个 mutations.
  4. export const useConfigStore = defineStore('config', {
  5. state(){ // 存放的就是模块的变量
  6. return {
  7. isMobile: (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))?true:false,
  8. isEur: window.location.hostname.includes('eur'),
  9. isTest: window.location.hostname.includes('test'),
  10. }
  11. },
  12. getters:{ // 相当于vue里面的计算属性,可以缓存数据
  13. getIsMobile(state){
  14. return (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))?true:false
  15. },
  16. },
  17. actions:{ // 可以通过actions 方法,改变 state 里面的值。
  18. refreshModel(){
  19. this.isMobile = (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))?true:false
  20. }
  21. }
  22. })