📚
note
Blog
  • Initial page
  • JS-notes
    • 使用浏览器书签执行js代码
    • JSON.stringify的小技巧
    • Fisher–Yates shuffle洗牌算法
    • 打印页面
  • Web-notes
    • 在网页中引入在线字体
  • Uniapp-notes
    • swiper-item高度自适应
    • 微信小程序的图片预览兼容性处理
  • VUE-notes
    • vue-note
    • vue3-note
  • VPS-notes
    • CentOs7笔记
    • ssh小记
    • Ubuntu笔记
    • vps安全相关
    • [Google Drive笔记](VPS-notes/Google Drive笔记.md)
  • TypeScript-notes
    • ts热编译项目
    • TypeScript笔记
    • js项目转ts
  • Python-notes
    • Python爬虫笔记
    • Python笔记
  • PHP-notes
    • php笔记
    • php+redis
    • php-codeIgniter
    • php抽奖算法
    • Laravel笔记
  • Mobile-notes
    • 移动端常用样式及兼容相关
  • Linux-notes
    • linux常用指令
  • Game-notes
    • Minecraft-server
  • TelegramBot-notes
    • tg-bot小记
  • Windows-notes
    • window-note
    • node-note
    • WSL-note
  • RaspberryPi-notes
    • RaspberryPi-note
    • 其他玩法
    • Openwrt
    • Ubuntu安装指南
  • Phone-notes
    • ZenFone6-note
  • Cocos-notes
    • Cocos-note
  • Network-notes
    • 单线复用
  • Other-notes
    • 国际化地域标识码
Powered by GitBook
On this page

Was this helpful?

  1. VUE-notes

vue-note

Last updated 2 years ago

Was this helpful?

Vue DOM元素绑定动态style

:style="{ transform: 'translateY(-' + num1 + 'px)' }"

Vue dom元素绑定多个类名需要以数组的方式书写

:class="[item.colorAndBoxName,
         current1==item.id?'selected1':'',
         current2==item.id?'selected2':'',
         current3==item.id?'selected3':'']"

requestAnimationFrame方法写动画

let animation3Func = function() {
    // do something...
    // 需要执行自调用来执行动画效果
    self.animalId3 = window.requestAnimationFrame(animation3Func);
  };
self.animalId3 = window.requestAnimationFrame(animation3Func);
//清除这个动画效果
window.cancelAnimationFrame(this.animalId3);

Vue使用clipboard(将指定数据存储到剪贴板)

使用clipboard 2全局注册

import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)

全局注册时用法

<template>
<div class="container">
    <input type="text" v-model="message">
    <button type="button"
      v-clipboard:copy="message"
      v-clipboard:success="onCopy"
      v-clipboard:error="onError">Copy!</button>
  </div>
</template>

<script>
new Vue({
  el: '#app',
  template: '#t',
  data: function () {
    return {
      message: 'Copy These Text'
    }
  },
  methods: {
    onCopy: function (e) {
      alert('You just copied: ' + e.text)
    },
    onError: function (e) {
      alert('Failed to copy texts')
    }
  }
})
</script>

使用clipboard局部组件注册

<span ref="copy"
      data-clipboard-action="copy"
      :data-clipboard-text="arr"
      @click="copy">复制结果</span>
import clipboard from "clipboard";
export default {
  data(){
    return{
      //动态数组
      arr:[],
      //存储clipboard实例
      copyBtn: null,
      //状态码
      status: 0,
      //待复制内容
      message: ""
    }
  },
    mounted() {
    // 初始化clipboard绑定事件
    //refs里的元素是点击时执行复制操作的按钮
    this.copyBtn = new clipboard(this.$refs.copy);
  },
  methods:{
    copy: function() {
      let _clipboard = this.copyBtn;
      let self = this;
      _clipboard.on("success", function(e) {
        self.status = 1;
        self.message = "你已复制到如下号码:" + e.text;
      });
    }
  },
  watch: {
    status(e) {
      if (e === 1) {
        alert(this.message);
        this.status = 0;
      }
    }
  },
}

Vue脚手架搭建的项目无法热更新解决方法

修改vue.config.js

module.exports = {
  devServer: {
    disableHostCheck: true
  }
}

Vue项目build时移除console.log

1. 第一种方法

  1. 安装 babel-plugin-transform-remove-console

  2. 修改 babel.config.js 文件

let transformRemoveConsolePlugin = []
if (process.env.NODE_ENV === 'production') {
  transformRemoveConsolePlugin = ['transform-remove-console']
}

module.exports = {
  plugins: [
    ...transformRemoveConsolePlugin
  ]
}

2. 第二种方法

1.安装 terser-webpack-plugin 2.修改 vue.config.js 文件

const TerserPlugin = require('terser-webpack-plugin')

module.exports = {
  configureWebpack: config => {
    config
      .optimization = {
        minimizer: [
          new TerserPlugin({
            terserOptions: {
              compress: {
                drop_console: true
              }
            }
          })
        ]
      }
  }
}

VS Code调试vue代码

  1. vscode 安装 Debugger for Chrome 扩展

  2. 修改 vue.config.js

module.exports = {
  configureWebpack: {
    devtool: 'source-map'
  }
}
  1. 按F5 选择 Chorme 生成配置文件。

  2. 替换配置文件。

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "vuejs: chrome",
      "url": "http://localhost:8080",
      "webRoot": "${workspaceFolder}/src",
      "breakOnLoad": true,
      "sourceMapPathOverrides": {
        "webpack:///src/*": "${webRoot}/*"
      }
    }
  ]
}
  1. 如果提示 Can't find Chrome ,需要配置 runtimeExecutable 为浏览器可执行文件路径。

  2. 如果浏览器白屏并且 vscode 提示 Cannot connect to the target,则需配置 userDataDir 为 true.

vue2 Element-UI 按需引入

1. 安装插件

npm install @babel/preset-env -D

2. 编辑.babelrc

{  
    "presets": [["@babel/preset-env", { "modules": false }]],
    "plugins": [
      [
        "component",
        {
          "libraryName": "element-ui",
          "styleLibraryName": "theme-chalk"
        }
      ]
    ]
}

本节来源:

本节来源:

本节来源:

RAF参考教程
git地址
vue项目无法热更新的解决办法
build时移除console.log()代码
vscode调试代码