vue-router

How to add external JS scripts to VueJS Components

穿精又带淫゛_ 提交于 2019-11-26 16:01:32
I've to use two external scripts for the payment gateways. Right now both are put in the 'index.html' file. However, I don't want to load these files at the beginning itself. The payment gateway is needed only in when user open a specific component (using router-view). Is there anyway to achieve this? A simple and effective way to solve this, it's by adding your external script into the vue mounted() of your component. I will illustrate you with the Google Recaptcha script: <template> .... your HTML </template> <script> export default { data: () => ({ ......data of your component }), mounted()

Vue的学习之路(大纲)

懵懂的女人 提交于 2019-11-26 14:42:40
Vue的基本使用: 此处只是列举vue的基本知识大纲,具体的讲解请看下面的连接: http://jspang.com/post/vueNav.html 本文末尾会附上以下vue学习过程中的源码。 Vue基础部分 第一章:内部指令 1.v-if v-else v-show 2.v-for指令 :解决模板循环问题 3.v-text & v-html 4.v-on:绑定事件监听器 5.v-model指令 6.v-bind 指令 7.v-pre & v-cloak & v-once 第二章:全局API 1.Vue.directive 自定义指令 2.Vue.extend构造器的延伸 3.Vue.set全局操作 4.Vue的生命周期(钩子函数) 5.Template 制作模版 6.Component 初识组件 7.Component 组件props 属性设置 8.Component 父子组件关系 第三章:选项 1.propsData Option 全局扩展的数据传递 2.computed Option 计算选项 3.Methods Option 方法选项 4.Watch 选项 监控数据 5.Mixins 混入选项操作 6.Extends Option 扩展选项 第四章:实例和内置组件 1.实例入门-实例属性 2.实例方法 3.实例事件 4.内置组件 -slot讲解 Vue全家桶部分 第五章

How to make dynamic routes on the vue router?

大城市里の小女人 提交于 2019-11-26 11:41:45
问题 My MainNavBar component like this : <template> ... <v-list-item v-for=\"(item, index) in listMenu\" :key=\"index\" @click=\"goTo(item)\" > <v-list-item-content> <v-list-item-title>{{ item }}</v-list-item-title> </v-list-item-content> </v-list-item> ... </template> <script> export default { ... methods: { goTo(key) { this.$router.push({ name: key }); }, ...mapActions(\"dataStore\", [\"getMenu\"]) }, computed: { ...mapGetters(\"dataStore\", [\"listMenu\"]) } }; </script> listMenu taken from API

Passing props to Vue.js components instantiated by Vue-router

风格不统一 提交于 2019-11-26 09:46:41
问题 Suppose I have a Vue.js component like this: var Bar = Vue.extend({ props: [\'my-props\'], template: \'<p>This is bar!</p>\' }); And I want to use it when some route in vue-router is matched like this: router.map({ \'/bar\': { component: Bar } }); Normally in order to pass \'myProps\' to the component I would do something like this: Vue.component(\'my-bar\', Bar); and in the html: <my-bar my-props=\"hello!\"></my-bar> In this case, the router is drawing automatically the component in the

Vue.js面试题整理

≯℡__Kan透↙ 提交于 2019-11-26 05:29:19
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其实区别并不大。都是一种设计思想。主要就是 mvc中 Controller演变成 mvvm中的 viewModel。 mvvm主要解决了 mvc中大量的

How to add external JS scripts to VueJS Components

为君一笑 提交于 2019-11-26 02:30:04
问题 I\'ve to use two external scripts for the payment gateways. Right now both are put in the index.html file. However, I don\'t want to load these files at the beginning itself. The payment gateway is needed only in when user open a specific component ( using router-view ). Is there anyway to achieve this? 回答1: A simple and effective way to solve this, it's by adding your external script into the vue mounted() of your component. I will illustrate you with the Google Recaptcha script: <template>

vue-router路由

限于喜欢 提交于 2019-11-25 22:44:37
查询参数 查询参数其实就是在路由地址后面带上参数和传统的url参数一致的,传递参数使用query而且必须配合path来传递参数而不能用name,目标页面接收传递的参数使用query。 注意:和name配对的是params,和path配对的是query 使用方法: this.$router.push({ path: '/news', query: { userId: 123 }}); 路由路径可以用 this.$route.path 路由路径参数 this.$route.params 例如:/user/:id → /user/2044011030 → this.$route.params.id 路由查询参数 this.$route.query 例如:/user/search?name=sf → this.$route.query.name 来源: https://blog.csdn.net/crazywoniu/article/details/80942642 来源: https://www.cnblogs.com/zhizou/p/11314586.html

前端技术之:Vue.js应用回退或刷新界面时提示用户保存修改

痴心易碎 提交于 2019-11-25 21:33:42
在实际应用中,运营人员在编辑数据时不希望因不小心点击了浏览器的回退或刷新按钮导致花费了很长时间编辑的数据丢失。可以采用以下两种手段防止运营编辑时丢失数据: 在运营人员刷新页面或回退时,自动保留数据至浏览器端本地存储,在重新进入编辑页面时再将数据从本地存储中加载到编辑界面。 第二种方法是在运营人员刷新或回退时,强提示运营人员有修改的数据尚未保存,询问是否继续。 无认采用哪一种方式,在技术实现上,我们需要首先能够监听到用户执行回退或刷新页面的动作。 实际上,当用户执行页面刷新时,会触发 window 对象上的 onBeforeUnload 事件。所以,我们需要在页面加载时开始监听此事件。在Vue.js应用中,我们可以在Vue.js的 mounted 生命周期事件函数中开始监听。 mounted() { window.onbeforeunload = e => { if (!this.modified) { return; } // 通知浏览器不要执行与事件关联的默认动作 e.preventDefault(); // Chrome 需要 returnValue 被设置成空字符串 e.returnValue = ''; }; }, 有了以上的代码,只要我们在修改了数据以后,将 modified 的值改为true,则可以在刷新整个页面时弹出如下提示: 当用户点击上述对话框的[ 取消 ]按钮后

Vue-router如何进行参数传递

痴心易碎 提交于 2019-11-25 20:09:10
 第一种:get方法      传递值      <router-link :to="{path:'/test',query: {name: id}}">跳转</router-link>      接收值      this.$route.query.name      第二种:post方法      传递值      <router-link :to="{path:'/test',push: {name: id}}">跳转</router-link>      接收值      this.$route.params.name (在页面刷新的时候就会消失)      3      第三种:路由方法      传递值      //?问号的意思是该参数不是必传项//多个参数用/:id连接//path: '/Driver/CarManager/CarSettinghttp://zzdxjyzd.com/:car_id/:page_type',{ path: 'test/:name?', name: 'test', component: 'test.vue', props: true, },      接收值      props:{name:{required:false,default:''}} (页面刷新不消失,可以在路由配置中设置参数)      ----------------