-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any plan for docs of abstract components? #720
Comments
My understanding is that it's internal-only, but I'll ping @yyx990803 to double check. |
For now it is internal only. I'm interested to see more details about your use case though, that may help validate the idea and see whether we can make it public. |
I'm involved in a big data product.
To be honest, there could be a way to improve the design, so does technical design. Despite that, this looks like a typical use case for prefetching data (step 2 -> 3). Here's the sample prefetch component: <script>
export default {
name: 'prefetch',
abstract: true,
render: () => '',
props: ['api'],
watch: {
api (val) {
if (val) {
// Use fetch here for quick prototyping,
// Should use cancellable method in production.
fetch(val)
.then(response => response.json())
.then(data => {
this.$store.dispatch('prefetchData', data)
})
}
}
}
}
</script> In root component, <prefetch :api="dataPath"></prefetch> For now, the approach is experimental. And it's definitely not the only way to achieve such functionality, a util method could also do the job. So I couldn't say I need it desperately. I'm just trying to implement the idea that everything could be a component. If abstract components are meant to be internal only, I'm still ok with it. |
Hi, I asked a question on stackoverflow related to this issue. My use case is simple. I just want to have a component which will add a property to its child component but will not change html at all. From this: <div id="app" class="container">
<foo>
<p>hello</p>
</foo>
</div> To this: <div id="app" class="container">
<p>hello</p>
</div> |
There's not many responses since it was opened. And it's not the only way how I could meet my development task. Close the issue. |
Hi. I have run into a case where this might be pretty useful. I'm new to Vue, so there may already be a good solution for what I'm presenting. I looked through the docs and through issues and didn't see anything that might help. I'm working on a project that uses canvas pretty extensively to draw graphs. I've worked with React where creating abstract components isn't a problem. I guess that I assumed the case would be the same in Vue (not a criticism, Vue is the cat's pajamas). Let me explain the use case: I'd like to make a series of components that encapsulate drawing operations to a canvas. Think:
The idea is that a parent component handles the canvas and passes the context down into all the child abstract components, which handle drawing. My thinking is that this might provide a simple way of managing draw layers to the canvas and for maintaining drawing operation code. If you've ever worked on a project with lots of drawing, it usually ends up a pain to maintain. My point is that some 'view' elements aren't always DOM elements. The canvas is a pretty complex element and it'd be most excellent to use Vue components (and vuex) to manage the state of a canvas image. Having access to abstract components would make it somewhat easier to incorporate more robust drawing libraries as well. Anywho, just my two cents. |
@giodif This kind of pattern is actually very doable with Vue currently - I use it quite often. 🙂 You can see a simple example here using MapboxGL, though in a real-world context I like to use |
@chrisvfritz Thanks for the example, makes sense. |
Not to dredge up an old topic, but a really excellent use case for abstract components is if you're attempting to implement a port of the const StyledComponent = styled(ExistingComponent)`
color: red;
font-size: 12px;
` |
There are several built-in abstract components, such as
transition
,keep-alive
. However, the official guide doesn't tell the developers that they could also create their own.Here's a possible use case. If the user's network is very good, I may want to guess his/her behavior based on some rules, and prefetch some async data or routes. So I create a
prefetch
abstract component. When the user really does what I have guessed, the UI could response immediately.After read source code of the built-in abstract components, I found that there are pitfalls I didn't realize. For example, an abstract component may contain another abstract component. Then I start to worry whether I could use it the right way.
Is
abstract
designed to be internal only, or is there any plan for the docs?The text was updated successfully, but these errors were encountered: