Home > Web Front-end > JS Tutorial > How does form-create dynamically generate vue components? (code example)

How does form-create dynamically generate vue components? (code example)

不言
Release: 2019-01-18 10:28:51
forward
3532 people have browsed it

The content of this article is about how form-create dynamically generates vue components? (Code sample) has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Example

How does form-create dynamically generate vue components? (code example)

let rule = [
  {
    type:'row',
    children:[
      {
        type:'i-col',
        props:{
          span:12
        },
        children:[
          formCreate.maker.input('商品名称','goods_name','iphone'),
          formCreate.maker.number('商品加个','goods_price',8688)
        ]
      },
      {
        type:'i-col',
        props:{
          span:12
        },
        children:[
          formCreate.maker.dateTime('创建时间','create_at'),
          formCreate.maker.radio('是否显示','is_show').options([
            {value:1,label:'显示'},
            {value:0,label:'不显示'}
          ])
        ]
      }
    ]
  }
]
Copy after login

maker.create

Generate custom components by creating a virtual DOM

Generate

Maker

let rule = [
  formCreate.maker.create('i-button').props({
    type:'primary',
    field:'btn'
    loading:true
  })
]
$f = formCreate.create(rule);
Copy after login

The above code uses the maker generator to dynamically generate a loading iview button component

Json

let rule = [
  {
    type:'i-button',
    field:'btn'
    props:{
        type:'primary',
        field:'btn',
        loading:true
    }
  }
]
$f = formCreate.create(rule);
Copy after login

The above code dynamically generates a iview button component through json

#Modification

You can use the following two methods Method to dynamically modify the configuration items of the component

Modify the component generation rules through rule

rule[0].props.loading = false;
Copy after login

Get the component generation rules through the $f.component() method and modify it

$f.component().btn.props.loading = false;
Copy after login

maker.template

Generate custom components through templates, maker.createTmp method is the alias of this method

Generate

Maker

let rule = [
  formCreate.maker.template(&#39;<i-button :loading="loading">{{text}}<i-button>&#39;,new Vue({
    data:{
      loading:true,
      text:&#39;正在加载中...&#39;
    }
  }))
]
Copy after login

The above code uses the maker generator to dynamically generate a loading iview button component

Json

let rule = [
  {
    type:&#39;template&#39;,
    template:&#39;<i-button :loading="loading">{{text}}<i-button>&#39;,
    vm:new Vue({
      data:{
        loading:true,
        text:&#39;正在加载中&#39;
      }
    })
  }
]
$f = formCreate.create(rule);
Copy after login

The above code is to dynamically generate a iview button component through Json method

Modification

can be dynamically modified in two ways The value inside the vm component

gets the vm of the custom component via rule and modifies

rule[0].vm.text = &#39;加载完毕&#39;;
rule[0].vm.loading = false;
Copy after login

via $f. The component() method gets the vm of the custom component and modifies

$f.component().btn.vm.text = &#39;加载完毕&#39;;
$f.component().btn.vm.loading = false;
Copy after login

The above is the detailed content of How does form-create dynamically generate vue components? (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template