vuejs / vue

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
http://v2.vuejs.org
MIT License
207.41k stars 33.65k forks source link

Suggestion about templating #2221

Closed nullptr128 closed 8 years ago

nullptr128 commented 8 years ago

Hello!

I moved from KnockoutJS to Vue.js few weeks ago and I really love this framework, really good job. It is superior version of KnockoutJS with much improvements.

There is one thing though that is missing from KO for me - ability to use componentless template. It would be really great to have an ability to create a template that may be reused in my different places, especially in SPA applications. Of course we can create a new component but there are some things that do not neccesarily need another component instance.

Lets say I've following problem: http://pastebin.com/vqU0Qbvr

Now I must expand this view into three different list that are from three different sources. In Vue.js I have either create a component just for list-item which I would not like to because I feel it is unnecessary, or I could just ctrl+c and ctrl+v list two times, which is of course really bad move: http://pastebin.com/Z2wwheT5

In KnockoutJS I could solve this with custom template: http://pastebin.com/dTUbb75J

Is there a possiblity to add something like this into Vue.js?

nirazul commented 8 years ago

Isn't this need already satisfied with the use of partials? You can register them either globally or within a component and they can be used wherever you want them. They can even be dynamic (with a dynamic name attribute).

nullptr128 commented 8 years ago

Thank you! I've missed them in documentation.

Is there a possibility to pass some arguments to partials?

yyx990803 commented 8 years ago

Looking at your use case, you really should be using components. There's no notion about "not necessary to be a component"; if it's about reusing UI logic, then use components. It doesn't matter how big or small it is.

nirazul commented 8 years ago

Partials inherit data from their parent. if you want to pass data, that's independent from the parent component, you'd really want to create a component.