Monaca Onsen UI Discord Chat Github Repo

setAttribute doesn't work in v-onsen



  • I wish to toggle the type attribute in a <v-ons-input> from “password” to “text” but the console show this error:

    0_1518609892761_console_error.JPG

    The App.vue code:

    0_1518610015748_App_vue_code.JPG

    and the Password.vue component:

    0_1518610101331_Password_vue_code.JPG

    When I use “getAttribute” or “hasAtributte” the same thing happens.

    In pure Vue code it doesn’t produce errors, it works fine, the type toggle correctly.


  • Onsen UI

    @buscemi To begin with, I think it’s easier if you use :type="type" as a prop in your template instead of getting DOM elements and modifying them :sweat_smile:

    If you don’t want to do that, well, I guess your reference is getting a Vue element (v-ons-input), which is not a real DOM input. Try this.$refs.input.$el.setAttribute instead.



  • @Fran-Diox The second solution works fine. Thanks for your suggestions.