Article From:https://segmentfault.com/q/1010000011118856
Question:

For example, the following code, I want to do if (this.a = = ture) judgment before writing, otherwise it will not write, how to write?

Or, that’s the only way to judge

render:(h, params){
    if(this.a==true){
        return h('div', [
            h('Button', {
                props: {
                    type: 'primary',
                    size: 'small'
                },
                style: {
                    marginRight: '5px'
                },
                on: {
                    click: () => {
                        this.bookMn(params.index)
                    }
                }
            }, 'Management '),H ('Button', {Props: {Type:'success',Size:'small'},Style: {MarginRiGht:'5px'},On: {Click: () => {This.nextpage (params.index)}}}, 'body'"),...}else{H ('Button', {Props: {Type:'primary',Size:'small'},Style: {MarginRight:'5px'},On: {Click: () => {This.bookMn (params.index)}}}, 'management')...}}}

It feels like a lot of repetition.

I wonder if there is any other way of thinking.

Answer 0:

Handwritten render function is very unintuitive, it is recommended to configure JSX, using JSX with three yuan operator can be achieved.

Answer 1:

In this way, you can decide whether you are going to push in the array through a parameter of params.row, hoping to help you.

render: (h, params) => {
  let btns = []
  params.row.a && btns.push(
    h('Button', {
      props: {
        type: 'primary',
        size: 'small'
      },
      style: {
        marginRight: '5px'
      },
      on: {
        click: () => {
          this.bookMn(params.index)
        }
      }
    }, 'Management '))Params.row.b & & btns.push (H ('Button', {Props: {Type:'succesS',Size:'small'},Style: {MarginRight:'5px'},On: {Click: () => {This.nextpage (params.index)}}}, 'body'))REturn H ("div", BTNs)}

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *