控制面板>系统>高级系统设置>高级>环境变量
新建用户环境变量
NODE_PATH
(变量名),值就是
nodejs
安装路径(
C:\Program Files\nodejs
)
默认安装路径
编辑用户变量
Path
把
nodejs
路径直接添加在后面即可
Vue报错Uncaught TypeError: Cannot read property 'match' of undefined
vue页面后退控制台报错
是因为
a
标签没有设置
href
属性,加上
href
属性就好了
vue-awesome-swiper 使用loop:true后点击事件不生效的问题
<template>
<swiper class="swiper" :options="swiperOption">
<swiper-slide @click="next">Slide 1</swiper-slide>
<swiper-slide>Slide 2</swiper-slide>
<swiper-slide>Slide 3</swiper-slide>
<swiper-slide>Slide 4</swiper-slide>
<swiper-slide>Slide 5</swiper-slide>
<div class="swiper-pagination" slot="pagination"></div>
<div class="swiper-button-prev" slot="button-prev"></div>
<div class="swiper-button-next" slot="button-next"></div>
</swiper>
</template>
<script>
import { swiper, swiperSlide } from "vue-awesome-swiper";
import "swiper/swiper-bundle.css";
export default {
name: 'swiper-example-loop',
components: {
swiper,
swiperSlide
data() {
return {
swiperOption: {
slidesPerView: 1,
spaceBetween: 30,
loop: true,
pagination: {
el: '.swiper-pagination',
clickable: true
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev'
methods:{
next(){
console.log(11)
</script>
会发现loop
出来的点击事件不生效
data() {
let vm=this;
return {
swiperOption: {
slidesPerView: 1,
spaceBetween: 30,
loop: true,
pagination: {
el: '.swiper-pagination',
clickable: true
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev'
on:function(e){
vm.next(e)
js动态往body添加dom
let elem = document.createElement("div");
elem.className='loading' ;
elem.innerHTML = `<div class="load-3">
<div class="indexLine"></div>
<div class="indexLine"></div>
<div class="indexLine"></div>
</div>`;
document.body.appendChild(elem);
监听页面关闭或刷新执行
window.onbeforeunload = function (e) {
e = e || window.event;
if (e) {
localStorage.removeItem("ax");
在vue
中使用
created(){
window.addEventListener('beforeunload', this.leaveConfirm)
methods: {
leaveConfirm (e) {
e = e || window.event
if (e) {
localStorage.removeItem('xx')
destroyed () {
window.removeEventListener('beforeunload', this.leaveConfirm);
Vue无痕刷新
<template>
<div id="app">
<router-view v-if="isRouterAlive" />
</div>
</template>
<script>
export default {
name: "App",
provide() {
return {
reload: this.reload
data() {
return {
isRouterAlive: true
methods: {
reload() {
this.isRouterAlive = false;
this.$nextTick(function() {
this.isRouterAlive = true;
</script>
<style>
</style>
<script>
export default {
inject: ['reload'],
data() {
return {};
methods: {
refresh(){
this.reload();
</script>
还有两种方法(体验一般)
这两种都可以刷新当前页面的,缺点就是相当于按ctrl+F5
强制刷新那种,整个页面重新加载,会出现一个瞬间的空白页面,体验不好
location.reload()
this.$router.go(0)
先跳转一个空白页,再跳转回来,这种方法就是地址栏url会有瞬间变化
<template>
<div></div>
</template>
<script>
export default {
mounted() {
let redirect = this.$route.query.redirect;
this.$router.replace(redirect);
</script>
<style lang="less" scoped>
</style>
ElementUI DatePicker选择月当前月份高亮样式修改
<template>
<div class="home">
<el-date-picker
v-model="value2"
type="month"
popper-class="month"
placeholder="选择月"
</el-date-picker>
</div>
</template>
<script>
export default {
name: "Home",
data() {
return {
value2: new Date(2021, 8, 1),
</script>
<style lang="less">
.month {
.el-month-table {
td.today {
.cell {
font-weight: normal !important;
color: unset !important;
</style>
Css实现滚动时隐藏滚动条
html {
-ms-overflow-style:none;
overflow:-moz-scrollbars-none;
html::-webkit-scrollbar{
width:0px
Vue install 使用
const plugin = {
install(Vue, opts = {}) {
console.log(opts);
Vue.directive('copy', {
bind(el, { value }) {
el.$value = value
el.handler = () => {
if (!el.$value) {
console.log('无复制内容')
return
const textarea = document.createElement('textarea')
textarea.readOnly = 'readonly'
textarea.style.position = 'absolute'
textarea.style.left = '-9999px'
textarea.value = `${el.$value} - ${opts.name}`
document.body.appendChild(textarea)
textarea.select()
const result = document.execCommand('Copy')
if (result) {
console.log('复制成功')
document.body.removeChild(textarea)
el.addEventListener('click', el.handler)
componentUpdated(el, { value }) {
el.$value = value
unbind(el) {
el.removeEventListener('click', el.handler)
export default plugin
在main.js中引入
import copy from './assets/js/plugin'
Vue.use(copy,{name:'shadow'})
jsonp判断url是否能打开
$.ajax({
url:'http://ybj.zj.gov.cn/art/2019/8/7/art_1229225623_1181747.html',
cache: false,
dataType: "jsonp",
processData: false,
timeout:10000,
complete: function (data) {
if(data.status==200){
}else{
获取Url参数(兼容哈希)
let url='https://xxx.cn/phone/dist/index.html?dataOpenId=oppyn1BSQzOA4C1706jNWLUoaSnU&dataUserId=406f3640614511ebad49bd6e5d36a63a#/home'
getQueryString = (name, search) => {
search = search || window.location.search.substr(1) || window.location.hash.split("?")[1];
let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
let r = search.match(reg);
if (r != null) return unescape(r[2]); return null;
Elementel-cascader
级联选择器动态加载及回显
误区:默认不需要自己去加载第一层数据,会自动请求第一层数据
回显只需要传入address数组即选中的id回显会自动去请求回显
addressList设置空数组即可
<el-cascader
ref="cascaderAddr"
:props="addressProps"
v-model="address"
:options="addressList"
@change="addressChange"
></el-cascader>
<script>
export default {
name: "Home",
data() {
return {
addressList:[],
address:[],
addressProps:{
label:'title',
value:'key',
lazy: true,
lazyLoad(node, resolve){
const { level } = node;
const nodes = [];
homeRecommendApi.getTree({pId:node.value}).then(res=>{
res.data.map(item=>{
let obj = {
key: item.key,
title: item.title,
leaf: level >= 3,
nodes.push(obj);
resolve(nodes);
</script>
微信小程序使用Echarts控制台报错非法颜色none
在ec-canvas
文件夹下wx-canvas.js
文件的_initStyle()
方法中加入代码
使用force-use-old-canvas="true"
属性引起(该属性解决图表不随屏幕滚动问题)
<ec-canvas id="progressChart" canvas-id="mychart-bar" ec="{{ ecProgress }}" force-use-old-canvas="true">
</ec-canvas>
var styles = [
"fillStyle",
"strokeStyle",
"globalAlpha",
"textAlign",
"textBaseAlign",
"shadow",
"lineWidth",
"lineCap",
"lineJoin",
"lineDash",
"miterLimit",
"fontSize",
styles.forEach((style) => {
Object.defineProperty(ctx, style, {
set: (value) => {
(style !== "fillStyle" && style !== "strokeStyle") ||
(value !== "none" && value !== null)
ctx["set" + style.charAt(0).toUpperCase() + style.slice(1)](value);
将字符串转换成数组("[上海, 天津, 河南]"
)
"[上海, 天津, 河南]".replace (/\[|]/g, '').split(',')
浙里办数据脱敏
const desensitization = (str, beginLen, endLen = -1) => {
let len = str.length;
if (beginLen == 0) {
endLen = endLen * len + 1;
let firstStr = str.substr(0, beginLen);
let lastStr = str.substr(endLen);
let middleStr = str.substring(beginLen, len - Math.abs(endLen)).replace(/[\s\S]/ig, '*');
return `${firstStr}${middleStr}${lastStr}`;
desensitization(userName,0)
desensitization(phone,3,-4)
desensitization(idCard,1,-1)
复制代码