ઓપ્શન્સ: વિવિધ (Options: Misc)
name
ઘટક માટે display name સ્પષ્ટ રીતે declare કરો.
ટાઇપ (Type)
tsinterface ComponentOptions { name?: string }વિગત (Details)
ઘટકનું name નીચેના માટે ઉપયોગ થાય છે:
- ઘટકના પોતાના template માં recursive self-reference
- Vue DevTools ના component inspection tree માં display
- Warning component traces માં display
જ્યારે તમે Single-File Components ઉપયોગ કરો છો, ત્યારે ઘટક પહેલેથી જ filename માંથી પોતાનું name infer કરે છે. ઉદાહરણ તરીકે,
MyComponent.vueનામની file ના inferred display name "MyComponent" હશે.બીજો case એ છે કે જ્યારે ઘટક
app.componentસાથે globally register થાય, ત્યારે global ID આપમેળે તેના name તરીકે set થાય છે.nameઓપ્શન inferred name ને override કરવાની, અથવા જ્યારે કોઈ name infer ન થઈ શકે (દા.ત. build tools ઉપયોગ ન કરતી વખતે, અથવા inlined non-SFC ઘટક) ત્યારે explicitly name provide કરવાની મંજૂરી આપે છે.એક case છે જ્યાં
nameexplicitly જરૂરી છે:<KeepAlive>નાinclude / excludeprops દ્વારા cacheable components સાથે match કરતી વખતે.TIP
Version 3.2.34 થી,
<script setup>ઉપયોગ કરતું single-file component filename ના આધારે આપમેળે તેનોnameઓપ્શન infer કરશે,<KeepAlive>સાથે ઉપયોગ કરતી વખતે પણ manually name declare કરવાની જરૂર દૂર કરે છે.
inheritAttrs
Default component attribute fallthrough behavior સક્ષમ કરવી કે નહીં તે નિયંત્રિત કરે છે.
ટાઇપ (Type)
tsinterface ComponentOptions { inheritAttrs?: boolean // default: true }વિગત (Details)
ડિફોલ્ટ રૂપે, parent scope attribute bindings જે props તરીકે ઓળખાતા નથી તે "fallthrough" થશે. આનો અર્થ એ છે કે single-root ઘટક હોય ત્યારે, આ bindings child ઘટકના root element પર સામાન્ય HTML attributes તરીકે apply થશે. જ્યારે target element અથવા અન્ય ઘટકને wrap કરતો ઘટક author કરો, ત્યારે આ હંમેશા ઇચ્છિત વર્તણૂક ન હોઈ શકે.
inheritAttrsનેfalseપર set કરીને, આ default behavior અક્ષમ (disabled) કરી શકાય. Attributes$attrsinstance property દ્વારા ઉપલબ્ધ છે અનેv-bindઉપયોગ કરીને non-root element ને explicitly bind કરી શકાય.ઉદાહરણ (Example)
<script setup>ઉપયોગ કરતા ઘટકમાં આ ઓપ્શન declare કરતી વખતે,defineOptionsmacro ઉપયોગ કરી શકો:vue<script setup> defineProps(['label', 'value']) defineEmits(['input']) defineOptions({ inheritAttrs: false }) </script> <template> <label> {{ label }} <input v-bind="$attrs" v-bind:value="value" v-on:input="$emit('input', $event.target.value)" /> </label> </template>આ પણ જુઓ
components
ઘટક ઇન્સ્ટન્સ માટે ઉપલબ્ધ કરવા registers ઘટકોનો ઓબ્જેક્ટ.
ટાઇપ (Type)
tsinterface ComponentOptions { components?: { [key: string]: Component } }ઉદાહરણ (Example)
jsimport Foo from './Foo.vue' import Bar from './Bar.vue' export default { components: { // shorthand Foo, // અલગ name હેઠળ register કરો RenamedBar: Bar } }
directives
ઘટક ઇન્સ્ટન્સ માટે ઉપલબ્ધ કરવા directives registers કરતો ઓબ્જેક્ટ.
ટાઇપ (Type)
tsinterface ComponentOptions { directives?: { [key: string]: Directive } }ઉદાહરણ (Example)
jsexport default { directives: { // template માં v-focus સક્ષમ કરે છે focus: { mounted(el) { el.focus() } } } }template<input v-focus>આ પણ જુઓ કસ્ટમ ડિરેક્ટિવ્સ