vue-router

Vue.js面试题整理(转载)

蓝咒 提交于 2019-12-02 16:12:07
一、什么是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其实区别并不大。都是一种设计思想。主要就是mvc中Controller演变成mvvm中的viewModel。mvvm主要解决了mvc中大量的DOM 操作使页面渲染性能降低,加载速度变慢,影响用户体验。 区别:vue数据驱动

How can I get query parameters from a URL in Vue.js?

▼魔方 西西 提交于 2019-12-02 16:01:45
How can I fetch query parameters in Vue.js? E.g. http://somesite.com?test=yay . Can’t find a way to fetch or do I need to use pure JS or some library for this? According to the docs of route object , you have access to a $route object from your components, that expose what you need. In this case //from your component console.log(this.$route.query.test) // outputs 'yay' More detailed answer to help the newbies of VueJs. <script src="https://unpkg.com/vue-router"></script> var router = new VueRouter({ mode: 'history', routes: [] }); var vm = new Vue({ router, el: '#app', mounted: function() { q

vue-router入门

夙愿已清 提交于 2019-12-02 15:18:47
概述 vue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用。 vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来。 传统的页面应用,是用一些超链接来实现页面切换和跳转的。 在vue-router单页面应用中,则是路径之间的切换,也就是组件的切换。 第一个单页面应用(01) 现在我们以一个简单的单页面应用开启vue-router之旅,这个单页面应用有两个路径: /home 和 /about ,与这两个路径对应的是两个组件Home和About。 1. 创建组件 首先引入vue.js和vue-router.js: < script src= "js/vue.js"> </ script> < script src= "js/vue-router.js"> </ script> 然后创建两个组件构造器Home和About: var Home = Vue.extend({ template: '<div><h1>Home</h1><p>{{msg}}</p></div>', data: function( ) { return { msg: 'Hello, vue router!' } } }) var About = Vue.extend({ template: '<div><h1>About</h1><p

vuejs application with different layouts (e.g. login layout, page layout, signup etc.)

冷暖自知 提交于 2019-12-02 14:22:35
I generated a project using vue-cli. I see project has one App.vue which is kinda main layout of the app - if I'm not mistaken. Here I put my basic HTML layout and <router-view></router-view> . Now the issue is that I need completely different layout for login (different wrappers , body has different classes) but I can't change it since App.vue has template which is kinda "fixed" as a layout. How to approach this issue? Is there recommended way? Should I create new component that represents layout so in that case my App.vue template would only have <router-view></router-view> and then

Vue.js Router Query Array

戏子无情 提交于 2019-12-02 12:19:52
问题 I'm trying to do is pass an array from query to the backend using Vue.js and router. So I have this method: submitForm () { this.$router.push({ name: 'AuctionResult', query: { models: this.selectedModels.map(e => e.value) } }) }, As a result will be query like this: ?models=MODEL1&models=MODEL2... But how can I make inputs look like array, like this: ?models[]=MODEL1&models[]=MODEL2... ??? I didn`t find anything in the documentation. 回答1: To support PHP / array style multi-values, you can

Vue 2 <keep-alive> not working with <router-view> and key

◇◆丶佛笑我妖孽 提交于 2019-12-02 11:31:11
问题 I'm using vue-router with a series of components like tabs. Each <router-link> is a tab and the space below is the <router-view> . Two of the tabs are the same component with different filters, let's say they are products and the router adds a parameter for filtering: /products/new & /products/sale . Inside of products are individual product components which get mounted when the route is opened. My problem is that when I switch between the routes, and the filter parameter is changed, the

vue-router的使用方式

橙三吉。 提交于 2019-12-02 09:14:45
step1:下载安装 npm i vue-router -S step2:main.js中引入 import VueRouter from 'vue-router' step3:安装插件 Vue.use(VueRouter) step4:创建路由对象并配置路由规则 let router = new VueRouter({ routes: [{ path: '/home', component: Home },{ path: '/error', component: Error },{ path: '/user', component: User },,{ path: '*', redirect: '/home' }] }) step5:将路由对象传递给Vue实例 step6:在app.vue中预留路由位置 step7:封装编程式导航的插件并注册至Vue https://blog.csdn.net/weixin_40825228/article/details/102490947 step8:使用 this.pop() this.push(/home) this.repalce(/error) 来源: https://blog.csdn.net/weixin_40825228/article/details/102748964

Detect Back Button in Navigation Guards of Vue-Router

大城市里の小女人 提交于 2019-12-02 09:13:40
How the route is changed, matters for my case. So, I want to catch when the route is changed by a back button of browser or gsm. This is what I have: router.beforeEach((to, from, next) => { if ( /* IsItABackButton && */ from.meta.someLogica) { next(false) return '' } next() }) Is there some built-in solutions that I can use instead of IsItABackButton comment? Vue-router itself hasn't I guess but any workaround could also work here. Or would there be another way preferred to recognize it? This is the only way that I've found: We can listen for popstate, save it in a variable, and then check

how to share data between components in VUE js (while creating list)

爱⌒轻易说出口 提交于 2019-12-02 08:41:28
Could you please tell me how to share data between components in VUE js (while creating list).I have two components list components and add todo component .I want to add items in list when user click on add button .But issue is input field present in different component and list is present in different component here is my code https://plnkr.co/edit/bjsVWU6lrWdp2a2CjamQ?p=preview // Code goes here var MyComponent = Vue.extend({ template: '#todo-template', props: ['items'] }); var AddTODO = Vue.extend({ template: '#add-todo', props: ['m'], data: function () { return { message: '' } }, methods:

Non-scoped styling in components applied only once when switching routes

时光总嘲笑我的痴心妄想 提交于 2019-12-02 06:45:46
问题 Vue.js documentation for Scoped CSS mentions that You can include both scoped and non-scoped styles in the same component I built the example application for vue-router and used two single file components instead of the string templates of the example - the rendering is as expected. I then tried to apply both scoped and non-scoped styles in the components. In the first one I have <style scoped> div { color: white; background-color: blue; } </style> <style> body { background-color: green; } <