vue-router

VUE - 路由的使用和重定向

放肆的年华 提交于 2020-01-24 03:29:48
什么是路由: 后端路由: 对于普通的网站,所有的超链接都是URL地址,所有的URL地址都对应服务器上对应的资源 前端路由:对于单页面应用程序来说,主要通过URL中的hash(#号)来实现不同页面之间的切换 前端路由的后端路由的区分 后端路由: 当我们在浏览器中输入http://192.168.1.200:8899/index.html来访问界面的时候,web服务器就会接收到这个请求,然后把index.html解析出来,并找到相应的index.html并展示出来,这就是路由的分发 前端路由 通过改变URL,在不重新请求页面的情况下,更新页面视图。 PS: 后端路由每次访问一个页面都要向浏览器发送请求,然后服务端再响应解析,这个过程就会存在延迟,但是对于前端路径来说只是访问一个新的界面,只是浏览器的路径发生了改变,没有和服务器进行交互(所以不存在延迟) 路由的创建和使用: 在使用Vue路由之前,我们必须要载入Vue-router库 < script src = "https://unpkg.com/vue-router/dist/vue-router.js" > < / script > < div id = "app" > < h1 > Hello App ! < / h1 > < p > < ! -- 通过router - link组件来导航 -- > < ! -- 通过传入 to

Open link in new window with Vuetify v-btn and Vue router

折月煮酒 提交于 2020-01-24 02:25:08
问题 Recent versions of Vue Router allow for links that open in a new tab, e.g. the following <router-link :to="{ name: 'fooRoute'}" target="_blank"> Link Text </router-link> correctly renders an <a target="_blank"> . However, the same doesn't seem to work with a Vuetify v-btn , which supports router paths, for example if we want to use an icon. <v-btn icon :to="{ name: 'fooRoute'}" target="_blank"> <v-icon>window</v-icon> Link Text </v-btn> Despite the component rendering an <a> , there is no

Vuex store is undefined in vue-router

有些话、适合烂在心里 提交于 2020-01-23 03:44:05
问题 I have a router and a global beforeEach hook to validate auth. import store from "@/store/store"; const router = new Router({ // routes... }); router.beforeEach((to, from, next) => { if (to.matched.some(record => record.meta.requiresAuth)) { if (!store.getters.getAccessToken) { //undefined store next("/access/login"); } } else { next(); } }); export default router; And in my store/store.js file, I have an action that makes a request to validate user/password, and then tries to redirect to /

Laravel - Vue.js application not working without php artisan serve

♀尐吖头ヾ 提交于 2020-01-23 02:53:04
问题 I have been trying to run my vue.js app with laravel, without php artisan serve But been seriously failing, here is my code: package.json: "axios": "^0.17", "bootstrap-sass": "^3.3.7", "cross-env": "^5.1", "jquery": "^3.2", "laravel-mix": "^1.0", "lodash": "^4.17.4", "vue": "^2.5.7", "vue-router": "^3.0.1" app.js: import './bootstrap' import router from './routes' const app = new Vue({ el: '#root', router }); routes.js: import VueRouter from 'vue-router' let routes = [ { path: '/', component:

Vue-绑定Class

心已入冬 提交于 2020-01-22 18:50:47
绑定Class的语法为 v-bind:class , 可以简写成 :class 绑定Class时,常用 绑定字符串、绑定对象,绑定数组,只有绑定对象时候,css的class引号可以省略 通常我们绑定Class时,可能会用到三目运算, 顺带每种绑定方式使用三目运算举例 一、绑定css中的class字符串 语法v-bind:class="‘样式class’", 引号不可以省略 三目运算 语法v-bind:class=" trueOrFalse ? ‘样式class1’:‘样式class2’" < html > < head > < script src = "https://unpkg.com/vue/dist/vue.js" > < / script > < script src = "https://unpkg.com/vue-router/dist/vue-router.js" > < / script > < style > . div { width : 200 px ; height : 200 px ; background - color : burlywood ; } . div1 { border - radius : 20 px ; } . div2 { width : 200 px ; height : 200 px ; background - color :

vue知识点,面试题考试

三世轮回 提交于 2020-01-22 06:43:41
vue面试题 1.Vue和react的相同与不同 相同点: 都支持服务器端渲染 都有virtual DOM,组件化开发,通过props参数进行父子组件数据的传递,都实现webComponent规范 数据驱动视图 都有支持native的方案,react native,Vue的weex 都有管理状态,react有redux,vue有自己的VueX 不同点: react严格上只针对MVC的view层,Vue则是MVVM模式 virtual DOM不一样,Vue会跟踪每一个组建的依赖关系,不需要重新渲染整个组件树。而对于react而言,每当应用的状态被改变时,全部组件都会重新渲染,所以react中会需要shouldcomponentUpdate这个生命周期函数方法来进行控制 组件写法不一样, React推荐的做法是 JSX + inline style, 也就是把HTML和CSS全都写进JavaScript了,即’all in js’; Vue推荐的做法是webpack+vue-loader的单文件组件格式,即html,css,jd写在同一个文件; .数据绑定: vue实现了数据的双向绑定,react数据流动是单向的 .state对象在react应用中不可变的,需要使用setState方法更新状态; 在vue中,state对象不是必须的,数据由data属性在vue对象中管理; 2

Redirect to requested page after login using vue-router

南笙酒味 提交于 2020-01-22 04:49:25
问题 In my application some routes are just accessible for authenticated users. When a unauthenticated user clicks on a link, for which he has to be signed in, he will be redirected to the login component. If the user logs in successfully, I would like to redirect him to the URL he requested before he had to log in . However, there also should be a default route , in case the user did not request another URL before he logged in. How can I achieve this using vue-router? My code without redirect

I use vue-router and jQuery in the template,when i switch router $(document).ready() is failure

橙三吉。 提交于 2020-01-21 19:42:48
问题 I do not know jQuery in vue correct usage. When I refresh page, $(document).ready() has a role. But when I switch the page through vue-router, $(document).ready() does not work. <template> <div id="photo_wrap"> <div class="photo_frame" v-for="(photo,index) in photos"> <img v-bind:src=" 'src/assets/photo/' + index + '.jpg' "> </div> </div> </template> <script> import $ from 'jquery' export default { name: 'photo', data() { return { photos: [ {},{},{},{},{} ] } } } $(function () { console.log(

基于Vue的WebApp项目开发(二)

限于喜欢 提交于 2020-01-20 18:34:37
利用webpack解析和打包.vue组件页面 相关知识: vue项目中的每个页面其实都是一个.vue的文件,这种文件,Vue称之为组件页面,必须借助于webpack的vue-loader才能运行,所以必须安装相关的包。 【注意】 从webpack2.0开始,在webpack.config.js中添加babel:{}是不认识的,需要在项目根目录下新建.babelrc文件,内容填写如下: { presets:['es2015'], //这句代码就是为了解决打包.vue文件不报错 plugins:['transform-runtime'] } View Code 好了,接下来看让一个Vue项目跑起来所需要的步骤: 步骤一:需要安装以下几个包 vue:vue.js核心包 vue-loader:.vue文件编译loader vue-template-compiler:.vue模板编译,被vue-loader所依赖 babel-plugin-transform-runtime:es6实时转换成es5语法 安装vue相关的依赖包(--save-dev意思是将包安装到开发环境下) 接着安装vue核心包(--save意思将包安装到运行环境下) 最终package.json文件内容 { "name": "vue", "version": "1.0.0", "description": "",

解决vue-router出现message: "Navigating to current location ("/admin/index") is not allowed"的问题

谁说我不能喝 提交于 2020-01-20 10:27:32
其原因在于Vue-router在3.1之后把$router.push()方法改为了Promise。所以假如没有回调函数,错误信息就会交给全局的路由错误处理,因此就会报上述的错误。 vue-router先报了一个Uncaught (in promise)的错误(因为push没加回调),然后再点击路由的时候才会触发NavigationDuplicated的错误(路由出现的错误,全局错误处理打印了出来)。 解决方案: 方案一(简单粗暴): 固定vue-router版本到3.0.7以下。这个方案没什么说的,就是简单粗暴,没有任何理由。 修改 vue-router 的 push 方法。 方案二(推荐): 找到路由文件,在 import Router from 'vue-router' 下面后添加如下代码: /** * 修改 vue-router 的push方法 */ const originalPush = Router . prototype . push ; Router . prototype . push = function push ( location , onResolve , onReject ) { if ( onResolve || onReject ) { return originalPush . call ( this , location , onResolve