Detect Back Button in Navigation Guards of Vue-Router

This is the only way that I’ve found: We can listen for popstate, save it in a variable, and then check that variable // This listener will execute before router.beforeEach only if registered // before vue-router is registered with Vue.use(VueRouter) window.popStateDetected = false window.addEventListener(‘popstate’, () => { window.popStateDetected = true }) router.beforeEach((to, from, next) => … Read more

Is it possible to change props value from method in Vue component?

What you are doing will throw a warning in Vue (in the console). [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop’s value. Prop being mutated: “propRoomSelected” The value will actually change inside the component, … Read more

Can we make vue.js application without .vue extension component and webpack?

As stated in this jsFiddle: http://jsfiddle.net/posva/wtpuevc6/ , you have no obligation to use webpack or .vue files. The code below is not from me and all credit goes to this jsFiddle creator: Create an index.html file: <script src=”https://npmcdn.com/vue/dist/vue.js”></script> <script src=”https://npmcdn.com/vue-router/dist/vue-router.js”></script> <script src=”/js/Home.js”></script> <script src=”/js/Foo.js”></script> <script src=”/js/router.js”></script> <script src=”/js/index.js”></script> <div id=”app”> <router-link to=”https://stackoverflow.com/”>/home</router-link> <router-link to=”/foo”>/foo</router-link> <router-view></router-view> … Read more

How to limit iteration of elements in `v-for`

You can try this code <div v-if=”showLess”> <div v-for=”value in array.slice(0, 5)”></div> </div> <div v-else> <div v-for=”value in array”></div> </div> <button @click=”showLess = false”></button> You will only have 5 elements in the new array. Update: Tiny change that makes this solution work with both arrays and objects <div v-if=”showLess”> <div v-for=”(value,index) in object”> <template v-if=”index … Read more

using async/await with webpack-simple configuration throwing error: RegeneratorRuntime not defined

In order to use await/async you will need to install a couple of Babel dependencies. This works with Vuejs project – npm install –save-dev babel-polyfill npm install –save-dev babel-plugin-transform-regenerator Once installed, you will need to modify your .babelrc file to use the plugin as follows – { “plugins”: [“transform-regenerator”] } and also your webpack.config.js file … Read more

Importing javascript file for use within vue component

Include an external JavaScript file Try including your (external) JavaScript into the mounted hook of your Vue component. <script> export default { mounted() { const plugin = document.createElement(“script”); plugin.setAttribute( “src”, “//api.myplugincom/widget/mykey.js” ); plugin.async = true; document.head.appendChild(plugin); } }; </script> Reference: How to include a tag on a Vue component Import a local JavaScript file In … Read more

Force download GET request using axios

You’re getting empty PDF ’cause no data is passed to the server. You can try passing data using data object like this axios .post(`order-results/${id}/export-pdf`, { data: { firstName: ‘Fred’ }, responseType: ‘arraybuffer’ }) .then(response => { console.log(response) let blob = new Blob([response.data], { type: ‘application/pdf’ }), url = window.URL.createObjectURL(blob) window.open(url) // Mostly the same, I … Read more