2

I'm trying to use data variable inside another data variable, but when I console it shows undefined. I'm trying to switch checkbox with setting data value true and false. My code is below,

data() {
        return {
            roleCreate:true,
            rows:[
              {
              id:1,
              type:0,
              create: `<label class="switch switch-primary mr-3">
                                <input type="checkbox"  ${this.roleCreate && 'checked'}>
                                <span class="slider"></span>
                            </label>`,
              }
            ]
       }
}

How can I do this?

2
  • why would you want to use a data variable instead of a normal template or a computed property? Commented Jul 2, 2020 at 8:25
  • @thks173 Sorry I didn't know how to use it, I'm new to vuejs. How can I do it? Commented Jul 2, 2020 at 8:28

1 Answer 1

1

I suppose that the rows property is not dynamic.

The HTML code belongs to the template and the javascript code belongs to the script.

Try to be modularized your code.

If rows is a dynamic property you can use v-for

data() {
    return {
        roleCreate:true
   }
}
<label class="switch switch-primary mr-3">
    <input v-if="roleCreate" type="checkbox">
    <span class="slider"></span>
  </label>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.