VueJS application doesn't work after browser "Back" function.
See original GitHub issueHey Jeffrey! Thank you for the solution, it was a nice idea.
But something is still wrong, could you please take a look? I’m not sure that this is related to the Turbolinks or your solution, it might be a VueJS bug, but anyway 😃
I created a really simple form using rails-slim template:
.row.justify-content-center
.col-sm-4
h2 Create a new account
= bootstrap_form_for @account do |f|
= f.text_field :name, 'v-model': 'name'
= f.primary 'Create Blog'
= javascript_pack_tag 'hello_vue'
It gives us an input field we need to use with VueJs:
<input type="text" name="account[name]" id="account_name" class="form-control">
And typical VueJs App:
import Vue from 'vue/dist/vue.esm'
import TurbolinksAdapter from 'vue-turbolinks'
document.addEventListener('turbolinks:load', () => {
const element = document.getElementById('new_account')
if (element != null) {
const accountName = new Vue({
el: element,
data: {
name: '362'
},
mixins: [TurbolinksAdapter]
})
}
});
And it works well when I went to the page (two way binding, and so on, I’m able to see it in console) Until I go to another page and come back twice 😃
Look:
Here you can see the initial state when the page is just opened. Then I got to another page and use browser “Back” button to return to the page with the New Account Form. When I did it the first time you still see 362 in the input field, but the VueJs App is already stopped and doesn’t work. When I returned the second time you can see that the field is empty at all 😃
What do you think about it? Did I miss something?
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
meta name= "turbolinks-cache-control" content= "no-cache"
in layout this helped meFixed in 1.1.1. Update the package and you should be good to go.