I've been itching to play around with Vue3.0 lately, and it feels great. So I quickly finished these issues of Vue2.0 and wrote some stuff for 3.0. nextTickFunction: Add a delayed callback after the next Dom update cycle ends. After modifying the data, you can get the updated Dom. Vue.nextTick( [callback, context] ) vm.$nextTick( [callback] ) // Usage 2 // Use as a Promise (new since 2.1.0) Vue.nextTick() .then(function () { // DOM updated}) illustrate: callback: delayed callback function Extensions:
MixinsFunction: Registers a mixin, affecting every Vue instance created after registration. Plugin authors can use mixins to inject custom behavior into components. // Inject a handler for the custom option 'myOption'. Vue.mixin({ created: function () { var myOption = this.$options.myOption if (myOption) { console.log(myOption) } } }) new Vue({ myOption: 'hello!' }) // => "hello!" illustrate: object: a vm attribute or method $forceUpdateFunction: Forces the Vue instance to re-render. vm.$forceUpdate() set, deleteFunction: Set and delete the properties of responsive data, and trigger view updates. // Usage 1 Vue.set( target, key, value ) Vue.delete( target, key ) // Usage 2 vm.$set( target, key, value ) vm.$delete( target, key ) illustrate: target: target object filterFunction: Used for some common text formatting and some standard data mapping. <!-- in double curly braces --> {{ message | capitalize }} <!-- In `v-bind` --> <div v-bind:id="rawId | formatId"></div> // Register filters: { capitalize: function (value) { if (!value) return '' value = value.toString() return value.charAt(0).toUpperCase() + value.slice(1) } } // Global registration Vue.filter('capitalize', function (value) { if (!value) return '' value = value.toString() return value.charAt(0).toUpperCase() + value.slice(1) }) new Vue({ // ... }) illustrate: Filter functions always receive the value of the expression (the result of the previous chain of operators) as the first argument.
directiveFunction: Used to register custom directives. usage: <!-- When the page loads, this element will receive focus --> <input v-focus> // Register a global custom directive `v-focus` Vue.directive('focus', { // When the bound element is inserted into the DOM... inserted: function (el) { // Focus element el.focus() } }) // Register a local directive. The component also accepts a directives option directives: { focus: // Definition of instruction inserted: function (el) { el.focus() } } } illustrate: inserted is just one of the interpolation functions of the registration instruction. The complete registration attributes can also include: Vue.directive('my-directive', { bind: function () {}, inserted: function () {}, update: function () {}, componentUpdated: function () {}, unbind: function () {} }) Other simple common properties and methods// console.log(vm.$root); vm.$root //Instance object vm.$el //Root element (real DOM element) // console.log(vm.$el); vm.$el.innerHTML //Get the content of the root element (real DOM element) // console.log(vm.$el.innerHTML); vm.$data //data object under the instance// console.log(vm.$data); vm.$options //Mount items under the instance// console.log(vm.$options); vm.$props //Data for communication between components// console.log(vm.$props); vm.$parent //In a component, it refers to the parent element // console.log(vm.$parent); vm.$children //In a component, refers to child elements // console.log(vm.$children); vm.$attrs //Used to get all attributes passed from the parent component // console.log(vm.$attrs); vm.$listeners //Used to get all methods passed from the parent component // console.log(vm.$listeners); vm.$slots //Slots in component// console.log(vm.$slots); vm.$scopedSlots //Used to access scoped slots // console.log(vm.$scopedSlots); vm.$refs //Used to locate DOM elements (using ref for tracking) // console.log(vm.$refs); vm.$watch //Used to monitor data (will be automatically destroyed after being used in the vue file) // console.log(vm.$watch); vm.$emit //Used to dispatch events (commonly used for data communication) // console.log(vm.$emit); vm.$on //Used to monitor event dispatching// console.log(vm.$on); vm.$once //Only listen to the event once (no more listening afterwards) // console.log(vm.$once); //Life cycle beforeCreate() { } created() { } beforeMount() { } mounted() { } beforeUpdate() { } updated() { } beforeDestroy() { } destroyed() { } SummarizeThis article mainly includes several commonly used APIs in vue. If you are interested in learning more, you can refer to its official website. I hope this article is useful to you and can be skillfully applied to actual project development. For easy reading and understanding, the code of this article has been uploaded to Github If there are any errors in the article, please point them out in the comment section. If it helps, please like and follow. The above is the detailed summary of Vue's commonly used APIs and advanced APIs. For more information about Vue's commonly used APIs and advanced APIs, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Analysis of MySQL's method of implementing fuzzy string replacement based on regular expressions
>>: Detailed tutorial on how to delete Linux users using userdel command
A list is defined as a form of text or chart that...
1. Installation Instructions Compared with local ...
Table of contents 1. Error phenomenon 2. Error An...
1. Use version vite:2.0 ant-design-vue: 2.0.0-rc....
This article uses examples to explain the concept...
The reason is that all files are encoded in utf8. ...
In a complex table structure, some cells span mul...
Judging from the results, there is no fixed patte...
Web front end 1 Student ID Name gender age 01 Zha...
Overview: I drew lessons from several timetable s...
I believe everyone has used JD. There is a very c...
When I was at work today, the business side asked...
1. Understand the WEB Web pages are mainly compos...
inline-flex is the same as inline-block. It is a ...
Preface Here are the steps to install and configu...