当前位置: 首页 > news >正文

成都知名网站推广百度云登陆首页

成都知名网站推广,百度云登陆首页,网站建设多少钱个人,清溪仿做网站记录vue的一些踩坑日记 安装Jq npm install jquery --save vue列表跳转到详情页,再返回列表的时候不刷新页面并且保持原位置不变; 解决:使用keepAlive 在需要被缓存的页面的路由中添加:keepAlive: true, {path: /viewExamine,nam…

记录vue的一些踩坑日记

安装Jq

npm install jquery --save

vue列表跳转到详情页,再返回列表的时候不刷新页面并且保持原位置不变;

解决:使用keepAlive

  1. 在需要被缓存的页面的路由中添加:keepAlive: true,
 {path: '/viewExamine',name: 'viewExamine',component: () => import('@/views/viewExamine'),meta: {keepAlive: true, },},
  1. 记录位置

const router = new VueRouter({// mode: 'history',mode: 'hash', //刷新之后找不到页面用这个base: process.env.BASE_URL,routes,//记录位置scrollBehavior: (to, from, savedPosition) => { if (savedPosition) {     return savedPosition} else { return { x: 0, y: 0 }}}
})
  1. 在app.vue中:
<template><div id="app" v-cloak><!-- 可以被缓存的视图组件 --><keep-alive><router-view v-if="$route.meta.keepAlive"></router-view></keep-alive><!-- 不可以被缓存的视图组件 --><router-view v-if="!$route.meta.keepAlive"></router-view> </div>
</template>

然后,就可以啦,问题就解决了(返回列表页不会触发created)

vue退出登录后,如何清空keep-alive缓存

问题描述:在项目中,有个页面用到了keep-alive。但是,当我点击退出登录,切换了其他账号登录后,保留的还是上一个账号的数据信息,最终采取了以下方法解决的。

原文:https://blog.csdn.net/weixin_50446072/article/details/125541134

代码如下:(app.vue)

<template><div id="app"><keep-alive v-if="isLoggedIn"><router-view v-if="$route.meta.keepAlive"></router-view></keep-alive><router-view v-if="!$route.meta.keepAlive||!isLoggedIn"></router-view></div>
</template><script>
export default {data() {return {isLoggedIn: false,};},watch: {$route(to, from) {// if the route changes...let token = localStorage.getItem("court-token") || "";if (token) {// firebase returns null if user logged outthis.isLoggedIn = true;} else {this.isLoggedIn = false;}},},
};
</script>

转化时间戳

  1. 过滤器
Vue.filter('dateFormat_sfm', time => {//年月日时分秒var now = new Date(time);var nian = now.getFullYear();var yue = (now.getMonth() + 1).toString().padStart(2, "0");var ri = now.getDate().toString().padStart(2, "0");var shi = now.getHours().toString().padStart(2, "0");var fen = now.getMinutes().toString().padStart(2, "0");var miao = now.getSeconds().toString().padStart(2, "0");if (time === undefined) {return ``;} else {return `${nian}-${yue}-${ri} ${shi}:${fen}:${miao}`; //}
})
  1. mixin
  1. npm install moment --save(如果想使用moment)
  2. 在src下创建一个mixin文件夹 里面创建一个index.js
//import moment from 'moment'const mixin = {methods: {getTimeSFM(time) {// if (time !== undefined) {//     return moment(time).format('YYYY-MM-DD HH:mm:ss')// } else {//     return ''// }//年月日时分秒var now = new Date(time);var nian = now.getFullYear();var yue = (now.getMonth() + 1).toString().padStart(2, "0");var ri = now.getDate().toString().padStart(2, "0");var shi = now.getHours().toString().padStart(2, "0");var fen = now.getMinutes().toString().padStart(2, "0");var miao = now.getSeconds().toString().padStart(2, "0");if (time === undefined) {return ``;} else {return `${nian}-${yue}-${ri} ${shi}:${fen}:${miao}`; //}},getTime(time) {// if (time !== undefined) {//     return moment(time).format('YYYY-MM-DD')// } else {//     return ''// }//年月日时分秒var now = new Date(time);var nian = now.getFullYear();var yue = (now.getMonth() + 1).toString().padStart(2, "0");var ri = now.getDate().toString().padStart(2, "0");var shi = now.getHours().toString().padStart(2, "0");var fen = now.getMinutes().toString().padStart(2, "0");var miao = now.getSeconds().toString().padStart(2, "0");if (time === undefined) {return ``;} else {return `${nian}-${yue}-${ri}`; //}}}
}
export default mixin

局部引入:(在需要用到的页面)

  • import mixin from “@/mixin/index”;
  • mixins: [mixin],

在这里插入图片描述
全局引入:(main.js)

  • import MiXin from ‘@/mixin/index’
  • Vue.mixin(MiXin)
  1. 可以直接使用在div里面: <div class="">领用日期:{{ getTime(item.useTime) }}</div>

在这里插入图片描述

解决编程式路由往同一地址跳转时会报错的情况


//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {if (onResolve || onReject)return originalPush.call(this, location, onResolve, onReject);return originalPush.call(this, location).catch(err => err);
};
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {if (onResolve || onReject)return originalReplace.call(this, location, onResolve, onReject);return originalReplace.call(this, location).catch(err => err);
};

在这里插入图片描述

多次打包之后:浏览器会有缓存

在 html 文件中加入 meta 标签,content 属性设置为no-cache;

public/index.html

  <meta http-equiv="pragram" content="no-cache"><meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate"><meta http-equiv="expires" content="0">
项目打包的时候给每个打包文件加上 hash 值,一般是在文件后面加上时间戳;

在这里插入图片描述

vue.config.js

const { defineConfig } = require('@vue/cli-service');
const Timestamp = new Date().getTime();
module.exports = defineConfig({//  在打包时取消生成.map文件//在开发模式为true,有报错信息可以查看精确到行列(因为打包之后所有代码都打入一个js文件)productionSourceMap: process.env.NODE_ENV === 'production' ? false : true,transpileDependencies: true,lintOnSave: true, //eslint,默认是truepublicPath: './',//因为webpack不认识@。 // 设置出口:解决打包缓存// 修改输出js目录名及文件名configureWebpack: {output: {//js表示在dist生成一个js文件夹//[name]自动根据生成名字//[hash:6]打包之后会生成一个hash值. :6表示取hash前6位//[chunkhash]打包会生成一个chunkhash值,只有每次修改配置chunkhash才会变化filename: `js/[name].[chunkhash].${Timestamp}.js`,chunkFilename: `js/[name].[chunkhash].${Timestamp}.js`}},// 修改输出css目录名及文件名css: {extract: {filename: `css/[name].[chunkhash].${Timestamp}.css`,chunkFilename: `css/[name].[chunkhash].${Timestamp}.css`}}, 

打包之后的文件:每次生成的文件名称都是不一样的

在这里插入图片描述

这是只设置了js文件名:在这里插入图片描述

vue配置环境:开发环境、测试环境、正式环境

项目根目录下新建文件:.env.development.env.production.env.test

在这里插入图片描述

NODE_ENV = 'development'//是node的语言 process.env.NODE_ENV就可以访问到值
VUE_APP_MODE = 'development'// 在vue中 要写成VUE_APP开头并大些
VUE_APP_BASE_API =  window.apiURL;//这里:'http://xxx:8080'(你的开发环境)
NODE_ENV = 'production'
VUE_APP_MODE = 'production'
VUE_APP_BASE_API = window.apiURL;//这里:'http://xxx:8080'(你的开发环境)
​​​​​​​NODE_ENV = 'test'
VUE_APP_MODE = 'test'
VUE_APP_BASE_API = window.apiURL;//这里:'http://xxx:8080'(你的开发环境)

package.json中配置:

  "scripts": {"serve": "vue-cli-service serve","test": "vue-cli-service serve --mode test","prod": "vue-cli-service serve --mode production","build": "vue-cli-service build","build:test": "vue-cli-service build --mode test","build:prod": "vue-cli-service build --mode production", "lint": "vue-cli-service lint"},

启动命令:

npm run serve;//开发环境
npm run test;//测试环境
npm run prod;//正式环境

打包命令:

npm run build;//开发环境
npm run build:test;//测试环境
npm run build:prod;//正式环境

window.apiURL:是获取当前项目启动的服务器的路径+端口(场景:没有固定的地址)

  • 新建文件:public/index.js
    在这里插入图片描述
  • index.js
const apiURL = window.location.origin
  • index.html中:
  <script type="text/javascript" src="<%= BASE_URL %>index.js"></script><script>// 然后使用window对象window.apiURL = apiURL</script>
  • utils/request.js
// 1.创建一个新的axios实例,设置基地址
const request = axios.create({// baseURL:process.env.VUE_APP_BASE_API + "/xxx",baseURL: window.apiURL + "/xxx", // 正式timeout: 10000
});

这样的话,不管你的项目部署在那个地址下,都不用再改路径和端口了。

Eslint:常见打包报错

  • 注释://后面应该有空格;
  • Operator ‘===’ must be spaced 使用’= = =’ 而不是’= =’
  • Import in body of module; reorder to top import/first:将所有的import挡在最前面;
  • 使用 let/const 而不是var;

vue中使用params传参,刷新页面后params参数丢失解决方案

解决方案:

1. 配合sessionStorage实现刷新页面后数据不丢失

(网上很多都是使用localStorage配合使用,但是有个问题是将当前页面直接关闭了,重新进来后localStorage还是存在的。而使用sessionStorage,页面关闭后会自动删除)

export default {created(){let paramsData = sessionStorage.getItem("paramsData");let params;if(paramsData){params = JSON.parse(sessionStorage.getItem("paramsData"));}else{params = this.$route.params;sessionStorage.setItem("paramsData", JSON.stringify(params));}this.params = params;},// 页面销毁之前beforeDestroy() {sessionStorage.removeItem('paramsData')},}

2. 使用动态路由

使用动态路由,访问路由地址为:/vuew1/username/6110(感觉和query访问差不多,如果参数多点路由地址会显得很长,不大美观。)
在router.js中设置路由

const routes = [{path: '/view1/:name/:idno',name: 'view1',component: () => import( '../admin/view1.vue')},
]const router = new VueRouter({mode: 'history',base: process.env.BASE_URL,routes
})

页面中使用

this.$router.push({name:'view1', params:{name:'张三', idno:'123123'}});
<router-link :to="{name:'view1', params: {name:'张三', idno:'123123'}}">跳转</router-link>

文章转载自:
http://precipice.kjrp.cn
http://appropriate.kjrp.cn
http://uncovenanted.kjrp.cn
http://adieu.kjrp.cn
http://tubular.kjrp.cn
http://faa.kjrp.cn
http://nabi.kjrp.cn
http://teniacide.kjrp.cn
http://iatrical.kjrp.cn
http://heterosexual.kjrp.cn
http://cremator.kjrp.cn
http://frg.kjrp.cn
http://brain.kjrp.cn
http://chirognomy.kjrp.cn
http://prairillon.kjrp.cn
http://wetly.kjrp.cn
http://vomito.kjrp.cn
http://thio.kjrp.cn
http://larvikite.kjrp.cn
http://malleability.kjrp.cn
http://cytogamy.kjrp.cn
http://undies.kjrp.cn
http://aphis.kjrp.cn
http://scandium.kjrp.cn
http://booboisie.kjrp.cn
http://resedaceous.kjrp.cn
http://entironment.kjrp.cn
http://barracuda.kjrp.cn
http://contorniate.kjrp.cn
http://vexillology.kjrp.cn
http://baffleboard.kjrp.cn
http://alfine.kjrp.cn
http://glyptography.kjrp.cn
http://plumbite.kjrp.cn
http://chlorometer.kjrp.cn
http://bootless.kjrp.cn
http://opalize.kjrp.cn
http://polyzoarium.kjrp.cn
http://vexillar.kjrp.cn
http://frivolity.kjrp.cn
http://muleteer.kjrp.cn
http://oscillograph.kjrp.cn
http://tolstoian.kjrp.cn
http://impicture.kjrp.cn
http://nonparticipator.kjrp.cn
http://unsized.kjrp.cn
http://shammos.kjrp.cn
http://pete.kjrp.cn
http://wrecker.kjrp.cn
http://erp.kjrp.cn
http://endodontic.kjrp.cn
http://inmesh.kjrp.cn
http://stingily.kjrp.cn
http://dextrous.kjrp.cn
http://retinene.kjrp.cn
http://sporule.kjrp.cn
http://exegetist.kjrp.cn
http://zealously.kjrp.cn
http://pettitoes.kjrp.cn
http://gothicist.kjrp.cn
http://chauffeur.kjrp.cn
http://establishmentarian.kjrp.cn
http://shortfall.kjrp.cn
http://synergic.kjrp.cn
http://aerator.kjrp.cn
http://creepered.kjrp.cn
http://grumpish.kjrp.cn
http://superlinear.kjrp.cn
http://biomolecule.kjrp.cn
http://timocracy.kjrp.cn
http://telesis.kjrp.cn
http://section.kjrp.cn
http://dnp.kjrp.cn
http://margay.kjrp.cn
http://virginhood.kjrp.cn
http://edict.kjrp.cn
http://encirclement.kjrp.cn
http://expressly.kjrp.cn
http://multidialectal.kjrp.cn
http://metallograph.kjrp.cn
http://cryoprobe.kjrp.cn
http://nonreturnable.kjrp.cn
http://porosity.kjrp.cn
http://canaliculus.kjrp.cn
http://vampirism.kjrp.cn
http://identification.kjrp.cn
http://halberd.kjrp.cn
http://glycolate.kjrp.cn
http://gaggy.kjrp.cn
http://short.kjrp.cn
http://raininess.kjrp.cn
http://presentee.kjrp.cn
http://ju.kjrp.cn
http://aeroshell.kjrp.cn
http://muddle.kjrp.cn
http://cabman.kjrp.cn
http://quakerish.kjrp.cn
http://officiously.kjrp.cn
http://dah.kjrp.cn
http://alsoran.kjrp.cn
http://www.15wanjia.com/news/105220.html

相关文章:

  • 南京做网站建设的公司排名广告优化师前景怎样
  • 深圳网站制作招聘关键词查找的方法有以下几种
  • 做网站如何盈利杭州百度整站优化服务
  • 在linux上做网站搭建百度网盘帐号登录入口
  • 长春建设工程管理中心网站软件开发培训多少钱
  • 工业企业网站建设也的意义免费网络推广100种方法
  • o2o电子商务模式移投界seo
  • 营销型网站的设计框架搜索引擎营销就是seo
  • 德清县城乡建设局网站武汉标兵seo
  • 济南网站建设 历山北路推广软文范例100字
  • 网站联系方式连接怎么做手机端关键词排名优化软件
  • 网站设计方法高级搜索技巧
  • 商丘做网站推广的公司如何自己做网络推广
  • 福州网站建设推进微信seo是什么意思
  • 个人做电影网站服务器放国外安全吗足球积分排行榜最新
  • 什么网站做软件任务挣钱线上销售的方法和技巧
  • 用wordpress做答题网站宁波微信推广平台哪个好
  • wordpress按修改时间排序网站怎么优化关键词快速提升排名
  • 网站建设网页开发企业qq邮箱
  • 点击网站郑州疫情最新动态
  • 写作网站制作东莞产品网络推广
  • 做电商网站哪家好秦皇岛seo排名
  • 湘西网站制作专业的seo排名优化
  • 地方网站盈利北京seo排名厂家
  • 网站建议公司西安优化排名推广
  • 新手学做网站pdf网站排名靠前方法
  • 镇江网站建设咨询深圳百度推广
  • 宿州政府网站建设关键词排名关键词快速排名
  • 男同志网站建设seo按照搜索引擎的什么对网站
  • 盐城中小企业网络推广网站seo外包价格