pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
vue/require-expose |
require declare public properties using `expose` |
v7.14.0 |
require declare public properties using
expose
This rule enforces the component to explicitly declare the exposed properties to the component using expose
. You can use expose
to control the internal properties of a component so that they cannot be referenced externally.
The expose
API was officially introduced in Vue 3.2.
<script>
/* ✓ GOOD */
export default {
expose: ['increment'],
data() {
return { count: 0 }
},
methods: {
increment() {
this.count++
}
}
}
</script>
<script>
/* ✗ BAD */
export default {
data() {
return { count: 0 }
},
methods: {
increment() {
this.count++
}
}
}
</script>
<script>
/* ✓ GOOD */
import { ref } from 'vue'
export default {
setup(props, { expose }) {
const count = ref(0)
function increment() {
count.value++
}
// public
expose({
increment
})
// private
return { count }
}
}
</script>
<script>
/* ✗ BAD */
import { ref } from 'vue'
export default {
setup(props) {
const count = ref(0)
function increment() {
count.value++
}
return { increment, count }
}
}
</script>
Nothing.
This rule was introduced in eslint-plugin-vue v7.14.0