# vue/require-expose
require declare public properties using
expose
- 💡 Some problems reported by this rule are manually fixable by editor suggestions (opens new window).
# 📖 Rule Details
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>
# 🔧 Options
Nothing.
# 📚 Further Reading
# 🚀 Version
This rule was introduced in eslint-plugin-vue v7.14.0