-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
General FAQ #96
Comments
Hi! Just started toying with vue.js and ran into an issue when nesting 2 data collections using "repeat" directives. Displaying the data is working fine -- however when an Element (with its subordinate VMs) is destroyed, bound data is currently removed as well (by the "hook:afterDestroy" listener). Example here: http://jsfiddle.net/sAa9X/ (try clicking any of the items.remove(n) buttons). Is this unintended behaviour, or is there a better approach I can use? |
interesting... I haven't considered this type of usage before. maybe I should remove that behavior. |
Hey Evan, first off I think you're doing a great job with vue. Thanks |
@dyu Thanks! This is a 20% project at the moment, but we've started using it in new projects here at Creative Lab, so there's potential that I can dedicate a more substantial part of my fulltime bandwidth to this in the future. |
I think I'd be in favour of this and handle related data explicitly (if necessary). Thanks for looking into it, I really enjoy using vue so far! |
@cmenke Thanks. After thinking about it, I think your suggestion makes sense. Originally I added that hook because I wanted to allow users to manually $destroy repeated instances in expressions, but now that I've seen your example, I believe it's problematic and in general a bad practice (not your example, but manually $destroying repeated vms). The proper way is simply manipulate the source data Array. So in the latest v0.8.5b patch I've reverted that behavior. |
Can you say a few words about how this is different / better than angular and where it's more suited? |
@Charuru there are a few reasons to use Vue over Angular, although they might not apply for everyone:
But also note:
|
The ^ above post would be great in a WiKi FAQ! |
Hi Evan, This week I've been evaluating what frontend framework I should use and arrived at Angular and React. Then I found yours, and I must say I really like the clear style of VueJS. I understand that Angular has the problem that it gets really slow when it creates a lot of watchers with for example ng-repeat. I found a nice article about that which says "The conventional wisdom for AngularJS says that you should keep the number of data-bound elements below 200." Now I wonder: Does VueJS have a similar problem with scaling of data-bound elements? Or is the fact that VueJS doesn't use dirty checking the winning factor? Then why does AngularJS use dirty checking at all? |
@yjeroen Angular gets slow when there are a lot of watchers, because every time anything in the scope changes, all these watchers need to be re-evaluated again. Vue.js doesn't suffer from this because under it uses an event based observing mechanism, so all changes trigger independently unless they have explicit dependency relationships. I believe Angular uses dirty checking because it had to support IE8. Vue.js is able to get the plain object syntax using ES5 features, which IE8 doesn't support. On the other hand, dirty checking also has the benefit that the original data objects are not modified in anyway (Vue.js converts object properties into getter/setters.) |
@yyx990803 |
@yjeroen
Apart from the above caveats, you can use Vue.js observed objects just like normal objects. |
I am trying to update array items in a Vue data object. I have tried using v-model: http://jsfiddle.net/obomoboe/HM9rn/1/ and have tried specifying a handler so that I can be specific about what I am assigning from/to: http://jsfiddle.net/obomoboe/HM9rn/2/ Neither one will update |
@adamgd sorry, this is one of the gotchas when you interpolate |
@adamgd an example fiddle: http://jsfiddle.net/HM9rn/3/ |
Hi Evan - I was wondering if there was anything on the horizon to release a more robust working example of Vue/Component. I saw on the Roadmap that there was some discussion on routing/page.js but I was curious if you or anyone had a sample project incorporating routing, page transitions, etc using component. I really like the way Vue structured, much more so than Angular, but I'm having trouble figuring out how I should structure my app. |
@mikegioia yes, that's definitely part of the plan. The first step is probably the |
@yyx990803, @brandonpierce: thank you both. I tested another fiddle with DOM mirroring of the data rather than interpolation: http://jsfiddle.net/obomoboe/HM9rn/4/ I now understand this quirk is to do with the interpolation (rather than something more fundamental to do with the change watching as I had initially thought after the response from @yyx990803). Is this 'gotcha' documented somewhere? |
@yyx990803 ok will do. Thanks again! |
@adamgd No it has not been documented, because interpolating objects is a pretty recent addition and there might be changes later. |
I have a question about vue.js's template initialization. Template is here. SvgComponent = Vue.extend({
template: """
<svg width=640 height=480>
<circle
cx=30 cy=30
r="{{size}}"
stroke="grey" stroke-width=1 />
</svg>
"""
data:{size: 25}
}) (sorry for coffeescript. javascript multiline text is bothersome) It occurs this error at first
This is simple reason why svg property What I want to ask is how vue.js can inject This is a same problem with angular/angular.js#1050 of angular but vue.js directive's (I know set Do you have any idea? Sorry for long post... |
The directive |
Ohhhh there was simple solution! I lost it and thought too difficult... anyway thx! |
Is it possible to use v-component (and other string-based directive) with an interpolated attribute, such as |
@ayamflow no, because edit: directives that start with the prefix are not interpolated at all. |
Would it be hard to implement a new partial behavior to be able to replace the element itself instead of it's innerHTML? <div>{{> my-partial}}</div> I think the syntax couldn't be much simpler than this: <div>{{< my-partial}}</div> The stripped down version of my problem: |
@marfalkov I don't think a replace partial syntax is the solution to your problem - I think something that allows conditional partial is. I'll look into it more later this week. |
@yyx990803 Conditional partials sounds really good. |
@abhijitghogre you can actually safely ignore this warning. You can suppress expression evaluation warnings by setting Or, initialize your data more specifically (although verbose, this has the benefits that you know what shape the ajax response looks like): data: {
college: {
status: {
name: ''
}
}
} |
Thanks Evan! |
Evan, I used this to set image src: <img v-attr="src: coverImagePath"> When I change 'coverImagePath' model, the image doesn't update. Any workaround? computed: {
coverImagePath: function () {
if (typeof this.college.cover_pic !== "undefined" && this.college.cover_pic !== '') {
return '/uploads/covers/college/' + this.college.cover_pic
}
return '/img/default_cover.jpg';
}
}, |
That should work. Can you show your code that creates and/or passes On Sat, Jun 27, 2015 at 11:20 AM, abhijitghogre [email protected]
|
coverImagePath should get computed automatically when college changes right? This is where 'college' model is changed (ajax success). methods: {
fetchCollege: function() {
$.ajax({
url: $('.showCollegeRoute').val(),
method: 'GET',
statusCode: {
200: function(response) {
this.college = response;
}.bind(this)
}
});
}
} And this is how it is declared in data: data: {
college: {}
}, |
@abhijitghogre Looks like it should work. Open an issue at vuejs/Discussion and make a fiddle reproduction please. |
Here is the fiddle: https://jsfiddle.net/pc2gg27y/5/ I have also created issue on Discussion repo vuejs/Discussion#216 |
I'm new to Vue, and attempting to render a JSON object returned by PHP using it's JSON_ENCODE function. Is there a simple way of loading this data into a list? |
@lusty15 has 38 participants and is closed, so that people don't spam with questions. I think it's best to ask questions like yours on vuejs/Discussion or in gitter channel of yyx990803/vue repo. As for you question, there is vuejs/vue-resource plugin for AJAX calls, you can use it to fetch JSON from server. |
Thank you. |
@yyx990803 Hi Evan. For starters really loving Vue.js. Great job! To my question: Is it possible to "trigger" jQuery-like events? I posted this question on StackOverflow, then came across this thread and thought it might help others who come across the same situation. |
@nicklaw5 why do you need the event in your method? If it carries some useful information (target element, or click coordinates), then I'd say it's better to create a dedication method with corresponding signature, and call this method from the click handler. The most common use case for having the event is to |
@sl-codenine v-model listens to |
@yyx990803 I've run into this before. Any reason the default non-lazy |
@yyx990803 Cool, that should work for me, thanks :) @JosephSilber probably that's because But i somewhat agree, that it could by default listen on |
is there any way to change several variables without rendering intermediate stages? |
@thecotne Vue's default behavior buffers the rendering until next event loop, so what you described should never happen. If you are running into problems, create an issue with a reproduction. |
I've never use a prop with an underscore. I'm not sure what it would On Fri, Aug 14, 2015 at 3:57 PM, Jason Daly [email protected]
|
What is the exact difference between |
@voyga see http://vuejs.org/guide/#Model
|
Is |
what's the dirty check using html string? when I use the Vue.Router,I can't change to other hashurl. |
@bpierre
|
I have an array of data in my Vue instance with Unix timestamps for each element. I'm looping over the data with I want people to be able to specify a range to filter by in plain English, so I'm trying to do this:
It seems as though it's not possible b/c if I return the array (or part of it) before the AJAX call, the filtering "works." However, if I return within the Should this work? Is there something I should do instead? |
@curtisblackwell |
@posva will do. Why not close/lock this then? |
Locked: Please ask questions or post information on the forums or the gitter chat. This is issue is no longer in use. |
Use this thread for simple, quick questions to avoid cluttering the issue list. Alternatively you can try the #vuejs IRC channel on freenode.
Also, read the wiki FAQ first.
The text was updated successfully, but these errors were encountered: