1234567891011121314151617181920212223 |
- import { defineStore } from 'pinia';
- // defineStore 方法有两个参数,第一个参数是模块化名字(也就相当于身份证一样,不能重复)
- // 第二个参数是选项,对象里面有三个属性,相比于vuex 少了一个 mutations.
- export const useConfigStore = defineStore('config', {
- state(){ // 存放的就是模块的变量
- return {
- 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,
- isEur: window.location.hostname.includes('eur'),
- isTest: window.location.hostname.includes('test'),
- }
- },
- getters:{ // 相当于vue里面的计算属性,可以缓存数据
- getIsMobile(state){
- 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
- },
- },
- actions:{ // 可以通过actions 方法,改变 state 里面的值。
- refreshModel(){
- 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
- }
- }
- })
|