Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Render function in vue

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use the Render function in vue". In the daily operation, I believe that many people have doubts about how to use the Render function in vue. The editor consulted all kinds of materials and sorted out a simple and easy-to-use operation method. I hope it will be helpful to answer the doubt of "how to use the Render function in vue". Next, please follow the editor to study!

First of all, the transformation of v-if uses the v value of the global component to determine the rendering state of the component, and the "nnum" of the props passed in the instance is worth controlling and can freely switch between the two states. In this way, you can use components like v-if.

Hahahhah ggggggggggggg Vue.component ('mycom', {render:function (createElement) {var s=this If (this.v==1) {return createElement ('div', {domProps: {innerHTML:'component n='+this.n}})} else {return createElement (' div', [this.$slots.slot1,this.$slots.slot2])}} Props: {v: {type:Number, default:0}, n: {default:'hello'}) Var app=new Vue ({el:'#app', data: {nnum:1}})

The use of v-for needs to use map

Hahahhah ggggggggggggg Vue.component ('mycom', {render:function (createElement) {if (this.v==1) {return createElement (' div', this.ar.map (function (item) {return createElement ('li') {domProps: {innerHTML:item}}))} else {return createElement ('div', [this.$slots.slot1,this.$slots.slot2])}} Props: {v: {type:Number, default:0}, n: {default:'hello'}, ar: {type:Array, default:function () {return Var app=new Vue ({el:'#app', data: {nnum:1, arr: [1, 2, 3, 4, 5, 6, 7, 8]})

Only the map method can detect the change, and other methods can not change the arr array in the corresponding state according to the change of the data. If you rely on the apply method to realize, you cannot detect the transformation of the this.ar to recalculate.

Return createElement ('div', Array.apply (null,this.ar.map (function (item) {return createElement (' li') {domProps: {innerHTML:'item'}}) hhah ggggggggggggg Vue.component ('mycom', {render:function (createElement) {if (this.v==1) {return createElement (' div') This.ar.map (function (item) {return createElement ('li') {domProps: {innerHTML:item}}))} else {return createElement ('div', Array.apply (null) This.ar.map (function (item) {return createElement ('li', {domProps: {innerHTML:'item'}}))})} Props: {v: {type:Number, default:0}, n: {default:'hello'}, ar: {type:Array, default:function () {return Var app=new Vue ({el:'#app', data: {nnum:2, arr: [1, 2, 3, 4, 5, 6, 7, 8]})

V-model uses domProps to implement two-way binding

You can use the assignment to value: to bind data to the default value of input, but changes to input cannot be passed to vue, which involves communication issues with components

So if you want to achieve two-way binding, you can only write your own events to start the delivery of vue shu'j.

DomProps: {value:self.v} hhah ggggggggggggg {{nnum}} Vue.component ('mycom', {render:function (createElement) {var self=this) Var inp=createElement ('input', {domProps: {value:self.v}}) Return createElement ('div', [inp])}, props: {v: {type:Number, default:0}, n: {default:'hello'}, ar: {type:Array, default:function () {return 55 (65]}}) Var app=new Vue ({el:'#app', data: {nnum:100, arr: [1, 2, 3, 4, 5, 6, 7, 8]})

Use input to trigger undateValue to update the nnum value in app (almost didn't turn the corner, when render is too complicated, you really find fault on your own)

{{nnum}} Vue.component ('mycom', {render:function (createElement) {var self=this) Var inp=createElement ('input', {domProps: {value:self.v}, on: {input:function (event) {self.$emit (' input') Event.target.value)}) Return createElement ('div', [inp])}, props: {v: {type:Number, default:0}, n: {default:'hello'}, ar: {type:Array, default:function () {return Methods: {update:function () {}) Var app=new Vue ({el:'#app', data: {nnum:100, arr: [1 this.nnum=parseFloat 2, 3 4, 5 5, 6 7, 8]}, methods: {updateValue:function (value) {this.nnum=parseFloat (value) }) at this point, the study on "how to use the Render function in vue" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report