2020-01-04 20:16:58 +08:00

1.5 KiB
Raw Blame History

VUE个人积累

使用VUE-cli创建的项目发布之前必须将 config/index.js 中 build 下的 productionSourceMap: true, 改为 productionSourceMap: false, 否则生产环境中可以看见所有的源码

vue-cookies

安装

npm install vue-cookies --save

使用

import VueCookies from 'vue-cookies'
Vue.use(VueCookies)

Api

设置 cookie this.$cookies.set(keyName, time) //return this

获取 cookie this.$cookies.get(keyName) // return value

删除 cookie this.$cookies.remove(keyName) // return false or true , warning next version return this use isKey(keyname) return true/false,please

查看一个cookie是否存在通过keyNamethis.$cookies.isKey(keyName) // return false or true

获取所有cookie名称 this.$cookies.keys() // return a array

nginx 配置

在vue路由模式为history的时候刷新页面会出现404问题。我们只需要在服务器配置如果URL匹配不到任何静态资源就跳转到默认的index.html。

server {
        listen 8105; // 表示你nginx监听的端口号
        root /home/admin/sites/vue-nginx/dist; // vue打包后的文件夹dist目录
        index index.html; 
        location / {
                 try_files $uri $uri/ /index.html; 
        }
}

常见问题

  • store的对象可以直接更改换另一个变量存着也是同一个内存地址尽量避免直接操作
    • var newObj = JSON.parse(JSON.stringify(obj)); 可以这样深拷贝