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

How to bind img src to data in Vue

If you’re using vue-cli you have to remember that everything is processed as a module, even images. You’d need to use require if the path is relative in JS, like this: { name: ‘test1’, src: require(“https://stackoverflow.com/questions/48847644/assets/logo.png”) } You can find a lot more details about this here: http://vuejs-templates.github.io/webpack/static.html

Scope Bootstrap Css in Vue

<style scoped src=”https://stackoverflow.com/questions/49653931/~bootstrap/dist/css/bootstrap.css”></style> <style scoped src=”~bootstrap-vue/dist/bootstrap-vue.css”></style> Update: a hack using SCSS Reason why the first solution won’t work: With scoped, the parent component’s styles will not leak into child components. If you want a selector in scoped styles to be “deep”, i.e. affecting child components, you can use the >>> combinator from the Vue doc … Read more

Integrating Google Maps in vue.js

I’d suggest using npm google-maps instead of adding a script in index.html. You might not need to call google-maps API in every pages, and I’d say it’s better to use Webpack properly. You can use npm install google-maps import GoogleMapsLoader from ‘google-maps’ mounted: function () { GoogleMapsLoader.load(function(google) { let map = new google.maps.Map(document.getElementById(‘map’), { zoom: … Read more

Refused to apply style from ” because its MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled

The usual reason for this error message is that when the browser tries to load that resource, the server returns an HTML page instead, for example if your router catches unknown paths and displays a default page without a 404 error. Of course that means the path does not return the expected CSS file / … 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

Visual Studio Code breakpoint appearing in wrong place

To answer this for any particular case, one would need the launch.json configuration being used, and the source folder structure, at minimum. I have a true story from just last week to illustrate why: Background I recently inherited a relatively small Vue project, and immediately encountered the same problem. Breakpoints in VSCode were “jumpy” in … Read more

Property ‘XXX’ does not exist on type ‘CombinedVueInstance’

As mentioned in the Typescript Support section of the Vue documentation: Because of the circular nature of Vue’s declaration files, TypeScript may have difficulties inferring the types of certain methods. For this reason, you may need to annotate the return type on methods like render and those in computed. In your case, you should change … Read more