pinia使用 piniaPluginPersist 持久化使用时候,添加persist属性时报错:没有与此调用匹配的重载

pinia使用 piniaPluginPersist 持久化使用时候,添加persist属性时报错:没有与此调用匹配的重载_第1张图片

 图片这种报错:添加persist,显示没有与此调用匹配的重载

原因:自己的问题是,在tsconfig.json中配置了 "target": "ES2020" (如下),然后就导致引入piniaPluginPersist的时候被当成组件使用就没有效果。(至于为什么,自己还不知道,大佬可以说哈)

{
    "compilerOptions": {
        "target": "ES2020",
        "useDefineForClassFields": true,
        "module": "ESNext",
        "lib": ["ES2020", "DOM", "DOM.Iterable"],
        "skipLibCheck": true,
        "allowJs": true,
        "typeRoots": ["./node_modules/@types", "./types"],
        "types": ["pinia-plugin-persist"],
        /* Bundler mode */
        "moduleResolution": "bundler",
        "allowImportingTsExtensions": true,
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": true,
        "jsx": "preserve",

        /* Linting */
        "strict": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "noFallthroughCasesInSwitch": true
    },
    "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
    "references": [{ "path": "./tsconfig.node.json" }],
    "paths": {
        "@/*": ["src/*"],
        "views/*": ["src/views/*"]
    }
}

 解决:后面tsconfig.json改成如下就可以正常写入

{
    "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
    "references": [{ "path": "./tsconfig.node.json" }],
    "compilerOptions": {
        "allowJs": true,
        "baseUrl": ".",
        "paths": {
            "@/*": ["./src/*"],
            "views/*": ["src/views/*"]
        }
    }
}

注意:persist需要写全。如下

    persist: {
        enabled: true,
        strategies: [
            { storage: sessionStorage, paths: ["counter"] }, // counter字段用sessionStorage存储
            { storage: localStorage, paths: ["name"] }, // name 字段用localstorage存储
        ],
    },

你可能感兴趣的:(vue.js,javascript)