-
-
Notifications
You must be signed in to change notification settings - Fork 5k
[Feature] A reload method like location.reload() #296
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
Comments
Lacking a reload method also prevents me from putting request promises in |
Having a reload route method would be nice. |
i think so ~~ Having a reload route method would be nice. |
having a force re-render on a specific v-for item would be even better |
@fnlctrl can you please elaborate in detail on your particular use case for this feature? I'm finding it difficult to reason why the entire router-view needs to be reloaded based on a status of a POST request. |
Here's what I think: after the POST request, what you really want to do is not reloading the component, but rather re-fetch the data. However you have placed the data-fetching logic in your component's lifecycle hooks, but that doesn't have to be the case. Consider: export default {
created () {
this.fetchData()
},
methods: {
fetchData () {
// fetch data
}
}
} After the POST request is resolved, you simply call |
@yyx990803 No that's not what I meant.. Consider this. route: {
data: ({to: {params: {someParam}}}) => ({
foo: $.get('/path/to/resource', {someParam}),
})
} Now, without a reload method, I will have to write |
It's like when it transitions from |
Hmm that makes sense, maybe a |
Looks good! |
On another thought, it might be more straightforward to just add an additional option to router.go({
path: '/a/1',
force: true
}) Then it will force the router to match the route even if it is the same with current route, and because all current components can be reused, only |
@yyx990803 In addition to the force option, would it make sense to add a |
Adding both would be nice, but in what scenario other than reloading would I use |
@coulix did you try |
I have a use case for this, and it was already mentioned by @liudangyi: #311 (comment)
|
any news about the force option ? :) |
Also interested in this feature. |
+1 for this feature too. |
+1 this feature!!! |
I would love this feature too! |
|
+1 this feature!!! It sounds like there is something like this already in place??? Can someone please confirm if that is the case. Thanks! |
+1 |
'Joshwoooooooooooooooooooooooooooooooong'.length
>> 39 |
@Joshwoooooooooooooooooooooooooooooooong |
what is my problem encountered is that i initialize my data with the property 'data',and i what to rerender them,how can i do |
Use
Then any other want to refresh their own routing page, you can do this:
If the $root is not router container,please use provide / inject to do this.知乎上我写了个完整版本的 |
|
I like the above solution! +1 |
It would make sense to add this also to router-link. In our case it's useful to perform some action (like hide dropdown) if route changes using |
My solution to refresh the component without reloading the url: router/index.js components/shared/Redirect.vue The action that trigger the refresh: |
watch: { that watch not call |
in vue-router3.0, it's work. this.$router.push({
name: 'path_key',
query: {
t: + new Date()
},
}); |
Here is my workaround to reload route without full page reload
and then just call
this method does not reload page at all and does not change variables value and I dont have to use session storage and restore it on page reload |
Here's my solution, which I use for links in a header, which when clicked should load a page or refresh it (scrolling to the top) if you're already on it. Add Now in your page component add this: beforeRouteUpdate (to, from, next) {
next() // IMPORTANT: *after* next() else the ?refresh sticks around half the time
this.checkRefresh()
},
created () {
this.checkRefresh()
},
methods: {
checkRefresh () {
// ?refresh to force refresh if clicking eg the icon/button in the header menu
// we make sure it doesn't stick around in the url bar for the user
if (this.$route.query.refresh !== undefined) {
this.loaded = false
this.$router.replace(this.$route.path)
} else {
this.fetchData()
}
},
fetchData () {
// ... anything you want to happen on create or update
}
} |
那不需要重新渲染页面改怎么办?我现在有个对话列表页面,类似qq。现在每次切换回来,页面被刷新了,我现在不需要刷新,该怎么写? |
I now have a conversation list page, similar to qq. Now every time I switch back, the page is refreshed. I don't need to refresh now. How to do? |
here is my solution:
then :
the |
Here is my solution to apply the refresh either while entering or leaving a page that requires a refresh. I do it like this because most of the time I require a page refresh is because I'm adding page specific content from outside of Vue (in my case via PHP) and I needed a way to get rid of it after leaving the route.
Hope it may be useful for someone. |
this will reload whole page |
I have actually found a pretty good solution using async function //all router request (load, page change...)
router.beforeEach(async(to, from, next) => {
console.log(await store.state.security.isAuthenticated);
if (to.matched.some(record => record.meta.requiresAuth)) {
// this route requires auth, check if logged in
// if not, redirect to login page.
//check auth in vuex store (also work with getters)
if (store.state.security.isAuthenticated) {
next();
} else {
next({
path:'/home',
query:{redirect:to.fullPath},//still useful when not logged in
});
await this.$router.go({
path:to.fullPath,
force:true
})
}
}else {
next(); // make sure to always call next()!
}
} No infinite loop at all, hope i can help... |
thanks :) |
有一个最简单粗暴的办法解决此问题:组件的name 值设置跟路由菜单里边的 name 只有不一样,每次重新点击菜单,就好重新渲染加载api 哈哈 |
reload method
deepcopy method
|
we can use forms also in some cases to realod the page |
I have a router-view that needs to be reloaded after sending some POST requests and receiving whether the operation was successful, but
doesn't trigger a reload even if the component's
route.canReuse
is set to false.Now I can only do
in the ajax callback to force the router-view to update itself, which is cumbersome.
Perhaps something like $route.router.reload() would be great, as it would be the counterpart of location.reload().
The text was updated successfully, but these errors were encountered: