Comments (6)
@posva I just realized in v3 directives are in fact implemented as special VNode data hooks - that is to say in render functions you can do this:
h('div', {
vnodeMounted() { ... },
vnodeUpdated() { ... }
})
And for template <div v-foo/>
, it will take the mounted
hook of v-foo
and merge it into the VNode as vnodeMounted
.
So they would be also included in the child component's this.$attrs
. If the child component does not bind $attrs
, the directive is ignored just like other extraneous attributes; if the child binds $attrs
, it binds the custom directives as well. This makes it consistent with the new attr fallthrough behavior. WDYT?
from core.
I think it will make sense to still support directives on components, even if we receive an array of elements. Some DOM manipulations like v-focus or v-clickaway are still valid for components. This will also make the adoption strategy a bit harder
from core.
@posva making the first argument Element | Array<Element>
is still a breaking change, in fact it requires heavier refactoring to make sure existing directives work properly. It's also not clear what a directive should do in the case of receiving multiple elements: what should v-focus
or v-clickaway
do in such cases? Implicitly failing seems like a bad idea.
from core.
making the first argument Element | Array is still a breaking change, in fact it requires heavier refactoring to make sure existing directives work properly
True, but it isn't much for existing directives to just extract the first element and throw if there are more (thinking of a possible codemod)
const [el] = elements
if (elements.length > 1) throw new Error()
For example, v-focus could lookup an input/select/button or explicitly tab-indexed element. For clickaway it could look up a data
attribute.
But my point is, recreating those features with components is way more verbose:
<Focus>
<v-text-field/>
</Focus>
or isn't declarative:
<v-text-field ref="mainInput"/>
this.$refs.mainInput.focus() // a component method
from core.
Just thinking out loud: Would this be achievable? And if so, would it make any sense? Would make the implementation treeshakable, right?
import {
beforeMount,
mounted,
beforeUpdate,
update,
beforeUnmount,
unmounted,
} from 'vue/directives'
export default () => {
mounted((el, binding, vnode, prevVnode) => {
// do stuff
})
}
from core.
Revised and published: vuejs/rfcs#32
from core.
Related Issues (20)
- IME language input binding issue (korean) HOT 1
- 关于Vue 3的v-model的bug报告 HOT 1
- Vite's define is not working in templates HOT 2
- Clearing `select`'s value in change handler behaviour changed since 3.4.15 via webdriver
- "Maximum recursive updates exceeded" message with Vue > 3.4.14 HOT 5
- vue 3.4.21 :where() style result is not as expected HOT 3
- TypeScript error (TS2590) when defining a prop as a union type of many (> 315) literal values and a non-primitive type
- v-bind shorthand (3.4) does not work with TS + "import * as"
- TypeError: Cannot read properties of null (reading 'parentNode') HOT 5
- Unnecessary re-render happened when using v-model HOT 2
- How to expose the expose method inside the element plus el input component for secondary encapsulation.
- withDefaults type error with tuples HOT 1
- In a Vue template, when writing a for loop and using Chinese variables, the parameter passed to the bound event is always the first value of the array. HOT 1
- Cannot read property 'isCE' of null in host component with slot using Module Federation
- Cannot read properties of undefined (reading 'shapeFlag');Page rendering error HOT 3
- Scoped style escape case
- vue使用tsx突然报 _defineComponent is not defined HOT 8
- a标签使用text属性时, 文本内容会被替换成text的属性值 HOT 2
- defineProps导致热更新失效 HOT 3
- `defineModel` loses two way binding flow when parent adds event listeneres HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.