0👍
In general, use a ref
to get your element instead of relying on jQuery or getElementById.
<select ref="theSelect" class="form-control" style="width: 50%">
mounted() {
$(this.$refs.theSelect).select2();
}
You might also want to bind the select’s value to a data member.
<select v-model='theValue' ref="theSelect" class="form-control" style="width: 50%">
And then add theValue
to your data option. Then you can just get and set the select’s value using this.theValue
. You can also watch
it and react to changes.
Finally, any other Vue
computed properties or directives that depend on theValue
will recalculate as needed.
Source:stackexchange.com