K
K
kokospro2018-08-09 14:55:27
Vue.js
kokospro, 2018-08-09 14:55:27

How to disable attribute inheritance in VueJs component?

I specify inheritAttrs: false for the VueJS component.
But the classes are still assigned to the root element.
what am I doing wrong?

<template>
  <div class="ui-input">
    <div v-if="label" class="ui-input__label">{{ label }}</div>
    <input class="ui-input__field"  v-on="$listeners" v-bind="$attrs" v-bind:value="value" v-on:input="$emit('input', $event.target.value)">
  </div>
</template>

<script>
  export default{
    name: 'ui-input',
   props:....
    inheritAttrs: false
  }
</script>

I use
<ui-input type="text"  class="form-control form-control-lg" label="Секретный ключ"></ui-input>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-06-23
@0xD34F Vue.js

I specify inheritAttrs: false <...> classes are still written to the root element

Regarding inheritAttrs the documentation says that
this option does not affect bindings classandstyle

So you can't turn it off. But it is possible to make the component functional ( for example ) - their attributes are not automatically assigned to the root element.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question