vue-router

How to use addroutes method in Vue-router?

a 夏天 提交于 2019-12-01 06:33:46
I have created a function "addroute()" to add routes dynamically,but it didn't work(the router does not changed). Is this a right way to use addRoutes method? I have learned this from tutorial. If not then give me a correct example,Thanks! ... const Bar={ template:'#panels', data(){ return {title:'badss'} } }; const Foo={ template:"#panels", data(){ return {title:'hell'} } }; const router = new VueRouter({ routes:[ {path:'/foo',component:Foo}, {path:'/bar',component:Bar} ] }); new Vue({ el:'#root', router:router, data:{ stats:stats }, methods: { // }, }); function addroute(){//watch here

vue-router creates always a new Component instance

允我心安 提交于 2019-12-01 06:22:14
问题 I found an issue in vue-router which triggers me a lot. Always when I switch between my routes, a new instance of the component is created. Further the old instances are not deleted and are running in background! I would expect that when I open a route, the old components will be destroyed or stop running. Is there a workaround to fix that issue? Here is a fiddle: https://jsfiddle.net/4xfa2f19/5885/ let foo = { template: '<div>Foo</div>', mounted() { console.log('Mount Foo with uid: ' + this.

How to config nginx for Vue-router on Docker

扶醉桌前 提交于 2019-12-01 05:43:32
问题 I'm setting up a docker image from nginx to serve a Vue app as static files. My vue app uses Vue-Router and it works perfectly on an other server. My nginx config is just like this: https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations And now I wanna migrate to docker, and this is my Dockerfile # build stage FROM node:9.11.1-alpine as build-stage WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build # production stage FROM nginx:1

How to redirect to a different url inside the vue-router beforeRouteEnter hook?

谁都会走 提交于 2019-12-01 02:59:21
I am building an admin page with Vue.js 2 and I want to prevent unauthenticated users from accessing the /admin route and redirect them to /login . For that I have used the In-Component Guard beforeRouteEnter in the Admin component like follows ... beforeRouteEnter(to, from, next) { if(userNotLogedIn) { this.$router.push('/login'); } } The problem here is that this is not defined in beforeRouteEnter hook. So what's the proper way to access $router and redirect to a different url in this case ? The documentation states that: The beforeRouteEnter guard does NOT have access to this , because the

前端面试题总结

倖福魔咒の 提交于 2019-12-01 01:37:58
前端面试题总结 Vue面试题 生命周期函数面试题 1.什么是 vue 生命周期 2.vue生命周期的作用是什么 3.第一次页面加载会触发哪几个钩子 4.简述每个周期具体适合哪些场景 5.created和mounted的区别 6.vue获取数据在哪个周期函数 7.请详细说下你对vue生命周期的理解? vue路由面试题 1.mvvm 框架是什么? 2.vue-router 是什么?它有哪些组件 3.active-class 是哪个组件的属性? 4.怎么定义 vue-router 的动态路由? 怎么获取传过来的值 5.vue-router 有哪几种导航钩子? 6.$route 和 $router 的区别 7.vue-router响应路由参数的变化 8.vue-router传参 9.vue-router的两种模式 10.vue-router实现路由懒加载( 动态加载路由 ) vue常见面试题 1.vue优点 2.vue父组件向子组件传递数据? 3.子组件像父组件传递事件 4.v-show和v-if指令的共同点和不同点 5.如何让CSS只在当前组件中起作用 6.<keep-alive></keep-alive>的作用是什么? 7.如何获取dom 8.说出几种vue当中的指令和它的用法? 9. vue-loader是什么?使用它的用途有哪些? 10.为什么使用key 11.axios及安装

How base option works in vue-router

隐身守侯 提交于 2019-12-01 00:17:23
问题 As par documentation of base option: The base URL of the app. For example, if the entire single page application is served under /app/, then base should use the value "/app/". But I have tried it like following, It does not seems to work: const router = new VueRouter({ base: "/app/", routes }) Demo fiddle. 回答1: The base has a default value of '/' . Drawing analogy from how it is used to route: <router-link to="home">Home</router-link> or <router-link :to="{ path: '/abc'}" replace></router

Vue.js, pass data to component on another route

断了今生、忘了曾经 提交于 2019-11-30 23:22:55
Simple task to pass data from one page to another made a real headache to newbie in Vue.js Here is my router I'm rendering a form on "/" page, which make an API request, and I just want to pass data to another route page with another component Is it so hard to do in Vue? It made a real headache for me today. Get data from API, save & send to another component. How can I do it? As Antony said, since you've already enabled props in router/index.js , you can pass parameters in router.push like this: router.push({ name: 'events', params: { items: data } }); then you will be able to receive items

Vue.js 2.0 transition on dynamic route not firing

别说谁变了你拦得住时间么 提交于 2019-11-30 22:42:26
I found that transition is not firing on dynamic route with parameters. For exemple with the code below, when I am in /chapter/1 and I go to /chapter/2 there is no transition. But when I am in /chapter/1 and I go to /profile/1 there is one ! main.js file require('normalize.css') import Vue from 'vue' import VueRouter from 'vue-router' import App from './App' import Panel from './components/Panel' import Profile from './components/Profile' window.bus = new Vue() Vue.use(VueRouter) const router = new VueRouter({ routes: [ { path: '/', redirect: '/chapter/1' }, { name:'chapter', path: '/chapter/

[ 转载 ] vue.js面试题一

て烟熏妆下的殇ゞ 提交于 2019-11-30 21:10:24
转载自:https://www.cnblogs.com/aimeeblogs/p/9501490.html 如有侵权 联系删除 Vue.js面试题整理 一、什么是 MVVM ? MVVM是 Model-View-ViewModel的缩写。 MVVM是一种设计思想。 Model 层代表数据模型,也可以在 Model中定义数据修改和操作的业务逻辑; View 代表 UI 组件,它负责将数据模型转化成 UI 展现出来, ViewModel 是一个同步 View 和 Model的对象(桥梁)。 在 MVVM架构下, View 和 Model 之间并没有直接的联系,而是通过 ViewModel进行交互, Model 和 ViewModel 之间的交互是双向的, 因此 View 数据的变化会同步到 Model中,而 Model 数据的变化也会立即反应到 View 上。 ViewModel 通过双向数据绑定把 View 层和 Model 层连接了起来,而 View 和 Model 之间的同步工作完全是自动的,无需人为干涉,因此开发者只需关注业务逻辑,不需要手动操作 DOM, 不需要关注数据状态的同步问题,复杂的数据状态维护完全由 MVVM 来统一管理。 二、 mvvm 和 mvc 区别?它和其它框架( jquery )的区别是什么?哪些场景适合? mvc和 mvvm其实区别并不大