1. Dynamic parametersStarting from 2.6.0, you can use a JavaScript expression enclosed in square brackets as a directive argument:
Here, attributeName will be dynamically evaluated as a JavaScript expression, and the resulting value will be used as the final parameter. For example, if your Vue instance has a data property attributeName with a value of "href", then this binding will be equivalent to v-bind:href. Likewise, you can use dynamic parameters to bind a handler function to a dynamic event name:
In this example, when the value of eventName is "focus", v-on:[eventName] will be equivalent to v-on:focus. Example: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Dynamic Parameters</title> <script src="vue.js"></script> </head> <body> <div id='app7'> <span v-on:[event_name]='dosomething'>{{msg}}</span> </div> </body> <script> var vm = new Vue({ el:"#app7", data:{ msg:100, event_name:'click' }, methods:{ dosomething:function(){ this.msg = this.msg + 1 } } }) </script> </html> 2. Calculated propertiesExpressions in templates are very convenient, but they are designed primarily for simple calculations. Putting too much logic in a template can make it cumbersome and difficult to maintain. For example:
At this point, the template is no longer just a simple declarative logic. You have to look at it for a while before you realize that what we want here is to display the reverse string of the variable message. It becomes even more difficult to handle when you want to include this flipped string in multiple places in your template. So, for any complex logic, you should use computed properties. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Computed Properties</title> <script src="vue.js"></script> </head> <body> <div id = 'app'>{{value_add}}</div> </body> <script> var vm = new Vue({ el:"#app", data:{ value:100 }, computed:{ //Similar to methods value_add:function(){ return this.value + 100 } } }) </script> </html> SummarizeThis is the end of this article about the use of dynamic parameters and calculated properties in Vue. For more relevant Vue dynamic parameters and calculated properties content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Summary of common Linux distribution mirror source configuration
>>: MySQL 5.7.25 installation and configuration method graphic tutorial
Need to know how many days there are before an im...
Preface Since vue3.0 was officially launched, man...
Docker Swarm is a container cluster management se...
This article shares the specific code of js to ac...
Configure Git environment in Docker At work, I en...
The happiest thing that happens in a production e...
This article shares with you how to use canvas an...
In daily development tasks, we often use MYSQL...
I just tried it on IE6, and it does show the toolb...
Click here to return to the 123WORDPRESS.COM HTML ...
Hyperf official website Hyperf official documenta...
This article shares the simple process of install...
For MySQL 5.5, if the character set is not set, t...
Table of contents 1. redo log (transaction log of...
1. Grammar location [=|~|~*|^~|@] /uri/ { ... } 2...