Home > Web Front-end > Vue.js > body text

[Organization and Sharing] Essential operating skills for Vue development, come and collect them!

青灯夜游
Release: 2022-07-21 20:13:44
forward
1623 people have browsed it

Mastering more skills will increase your programming efficiency. If you want to do your job well, you must first sharpen your tools. This article will share with you some essential Vue operation skills. I hope it will be helpful to you!

[Organization and Sharing] Essential operating skills for Vue development, come and collect them!(Learning video sharing:

vue video tutorial

)

Keyboard events

    For keys that do not provide aliases in
  • Vue, you can use the original key value to bind. The so-called key value is event.key Obtained value
  • If the
  • key value is a single letter, you can use it directly. If it is a camel case name consisting of multiple words, you need to split it and use - Connection
// 只有按下q键时才会执行send方法


// 只有按下capslock键时才会执行send方法
Copy after login
    For system modifiers
  • ctrl, alt, shift these comparisons For the use of complex keys, there are two situations
  • Because these keys can be pressed while pressing other keys to form a combination shortcut key
  • When the trigger event is
  • keydown , we can directly press the modifier to trigger
  • When the trigger event is
  • keyup, when pressing the modifier key, press other keys at the same time, and then release other keys , the event can be triggered.
// keydown事件时按下alt键时就会执行send方法


// keyup事件时需要同时按下组合键才会执行send方法
Copy after login
    Of course we can also customize the key alias
  • through
  • Vue.config.keyCodes. Custom key name = key code Define
// 只有按下回车键时才会执行send方法

    
// 13是回车键的键码,将他的别名定义为autofelix
Vue.config.keyCodes.autofelix=13
Copy after login
Picture preview

    We often need to use picture preview in projects,
  • viewerjs is a very cool picture preview Plug-in
  • Function support includes image enlargement, reduction, rotation, dragging, switching, stretching, etc.
  • Installation
  • viewerjsExtension
npm install viewerjs --save
Copy after login
    Introduce and configure the function
//引入
import Vue from 'vue';
import 'viewerjs/dist/viewer.css';
import Viewer from 'v-viewer';

//按需引入
Vue.use(Viewer);

Viewer.setDefaults({
    'inline': true,
    'button': true, //右上角按钮
    "navbar": true, //底部缩略图
    "title": true, //当前图片标题
    "toolbar": true, //底部工具栏
    "tooltip": true, //显示缩放百分比
    "movable": true, //是否可以移动
    "zoomable": true, //是否可以缩放
    "rotatable": true, //是否可旋转
    "scalable": true, //是否可翻转
    "transition": true, //使用 CSS3 过度
    "fullscreen": true, //播放时是否全屏
    "keyboard": true, //是否支持键盘
    "url": "data-source",
    ready: function (e) {
        console.log(e.type, '组件以初始化');
    },
    show: function (e) {
        console.log(e.type, '图片显示开始');
    },
    shown: function (e) {
        console.log(e.type, '图片显示结束');
    },
    hide: function (e) {
        console.log(e.type, '图片隐藏完成');
    },
    hidden: function (e) {
        console.log(e.type, '图片隐藏结束');
    },
    view: function (e) {
        console.log(e.type, '视图开始');
    },
    viewed: function (e) {
        console.log(e.type, '视图结束');
        // 索引为 1 的图片旋转20度
        if (e.detail.index === 1) {
            this.viewer.rotate(20);
        }
    },
    zoom: function (e) {
        console.log(e.type, '图片缩放开始');
    },
    zoomed: function (e) {
        console.log(e.type, '图片缩放结束');
    }
})
Copy after login
    Use the picture preview plug-in
  • Use a single picture

 
Copy after login
    Use multiple pictures

 
Copy after login
Marquee

    This is a fun special effects technique
  • For example, when you pick up people at the airport, you can use the marquee special effects on your mobile phone. Become the most handsome boy in the crowd
  • The marquee special effect is actually to delete the first text and add it to the last one, thus forming the effect of text movement




    
    跑马灯
    

    
                          

{{ msg }}

    
Copy after login
Countdown

    There are many applications for the countdown technique
  • For example, when there are many rush-buying products, we need to have a countdown to remind users of the time to start the rush
  • In fact, it is every other Seconds, recalculate the time and assign it to
  • DOM




    
    倒计时

    
        
抢购开始时间:{{count}}
    
Copy after login
Customized right-click menu

    In the project, we sometimes You need to customize the options that appear with the right mouse button instead of the browser's default right-click options
  • How to implement the right-click menu is actually very simple in
  • Vue, just use vue-contextmenujs Plug-in can be installed
  • vue-contextmenujs Plug-in
npm install vue-contextmenujs
Copy after login
    Introduction
//引入
import Vue from 'vue';
import Contextmenu from "vue-contextmenujs"

Vue.use(Contextmenu);
Copy after login
    How to use
  • You can use
  • You can add icons to options
  • You can use
  • style Style of label customization option
  • You can use
  • disabled You can click the attribute to disable the option
  • You can use
  • divided:true Set the underline of the option
  • You can use
  • children to set sub-options





Copy after login
Print function

    Supports printing function for web pages, which is also common in many projects
  • To use the printing function in Vue, you can use the
  • vue-print-nb plug-in
  • installation
  • vue-print-nb plug-in
npm install vue-print-nb --save
Copy after login
    Introducing printing service
import Vue from 'vue'
import Print from 'vue-print-nb'
Vue.use(Print);
Copy after login
    Use
  • Use the
  • v-print command to start the printing function
    

红酥手,黄縢酒,满城春色宫墙柳。

    

东风恶,欢情薄。

    

一怀愁绪,几年离索。

    

错、错、错。

    

春如旧,人空瘦,泪痕红浥鲛绡透。

    

桃花落,闲池阁。

    

山盟虽在,锦书难托。

    

莫、莫、莫!

Copy after login
JSONP request

  • jsonp is one of the main ways to solve cross-domain issues
  • So learn how to It is actually very important to use
  • jsonp in vue
  • Installation
  • jsonpExtension
npm install vue-jsonp --save-dev
Copy after login
    Registration Service
// 在vue2中注册服务
import Vue from 'vue'
import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)

// 在vue3中注册服务
import { createApp } from 'vue'
import App from './App.vue'
import VueJsonp from 'vue-jsonp'
createApp(App).use(VueJsonp).mount('#app')
Copy after login
    Usage method
  • It should be noted that after using
  • jsonp to request data, the callback is not then Instead of executing
  • in the custom
  • callbackName, it needs to be mounted on the window object
Copy after login
【 Related video tutorial recommendations:

vuejs entry tutorial, web front-end entry

The above is the detailed content of [Organization and Sharing] Essential operating skills for Vue development, come and collect them!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
vue
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!