Vue.js

Vue.js scroll to top of new page route after setTimeout

走远了吗. 提交于 2021-01-20 17:43:27
问题 I have a page transition that doesn't work nicely when the scroll to the top of a new route is instant. I'd like to wait 100ms before it automatically scrolls to the top. The following code doesn't end up scrolling at all. Is there a way to do this? export default new Router({ mode: 'history', routes: [ { path: '/', name: 'Home', component: Home } ], scrollBehavior (to, from, savedPosition) { setTimeout(() => { return { x: 0, y: 0 } }, 100); } }) 回答1: This is natively supported by Vue now,

【前端词典】Vuex 注入 Vue 生命周期的过程

僤鯓⒐⒋嵵緔 提交于 2021-01-20 15:31:50
前言 这篇文章是【前端词典】系列文章的第 13 篇文章,接下的 9 篇我会围绕着 Vue 展开,希望这 9 篇文章可以使大家加深对 Vue 的了解。当然这些文章的前提是默认你对 Vue 有一定的基础。如果一点基础都没有,建议先看官方文档。 第一篇文章我会结合 Vue 和 Vuex 的部分源码,来说明 Vuex 注入 Vue 生命周期的过程。 说到源码,其实没有想象的那么难。也和我们平时写业务代码差不多,都是方法的调用。但是源码的调用树会复杂很多。 为何使用 Vuex 使用 Vue 我们就不可避免的会遇到组件间共享的数据或状态。应用的业务代码逐渐复杂,props、事件、事件总线等通信的方式的弊端就会愈发明显。这个时候我们就需要 Vuex 。Vuex 是一个专门为 Vue 设计的状态管理工具。 状态管理是 Vue 组件解耦的重要手段。 它借鉴了 Flux、redux 的基本思想,将状态抽离到全局,形成一个 Store。 Vuex 不限制你的代码结构,但需要遵守一些规则: 应用层级的状态应该集中到单个 store 对象中 提交 mutation 是更改状态的唯一方法,并且这个过程是同步的 异步逻辑都应该封装到 action 里面 Vuex 注入 Vue 生命周期的过程 我们在安装插件的时候,总会像下面一样用 Vue.use() 来载入插件,可是 Vue.use() 做了什么呢?

Changing body styles in vue router

做~自己de王妃 提交于 2021-01-20 15:27:31
问题 I'm using Vue router with two pages: let routes = [ { path: '/', component: require('./components/HomeView.vue') }, { path: '/intro', component: require('./components/IntroView.vue') } ] This works fine, except that each of my components has different body styling: HomeView.vue: <template> <p>This is the home page!</p> </template> <script> export default { } </script> <style> body { background: red; } </style> IntroView.vue: <template> <div> <h1>Introduction</h1> </div> </template> <script>

Center content vertically on Vuetify

独自空忆成欢 提交于 2021-01-20 14:43:45
问题 Is there a way to center content vertically in Vuetify? With the text-xs-center helper class, the content gets centered horizontally only: <v-container grid-list-md text-xs-center> <v-layout row wrap> <v-flex xs12> Hello </v-flex> </v-layout> From the API, I tested some other helper classes such as align-content-center but did not achieve the result. 回答1: Update for new vuetify version In v.2.x.x , we can use align and justify. We have below options for setup the horizontal and vertical

How to watch prop even if it does not change?

可紊 提交于 2021-01-20 13:35:27
问题 I have watcher with the same name as a prop. The prop is dynamically set in a parent component on some event. I need something that triggers some function in the child component with property value every time the event is triggered on parent -even if the prop it set is the same. Is there any watcher option or other method of handling such case which would allow me to do that ? What I tried (this is in Post component): watch: { replyClicked: { handler(newVal, oldVal) { console.log(newVal,

Is there something to auto update this code in vue?

夙愿已清 提交于 2021-01-20 13:35:15
问题 I got this button in the navigator that shows up when a user is logged in and when the user logs out the button is gone. But now i need to refresh my page before the button removes/appears. Here is my code: Button: <div v-if="ingelogd"> <div class="w-2/12 hidden lg:flex" v-for="(data, index) in allIngelogds" :key="index"> <button @click="uitloggen" class="downloadbtn"> {{ data.uitloggenKnop }} </button> </div> </div> in data:() i return this: ingelogd: false and then i created a mounted()

Is there something to auto update this code in vue?

妖精的绣舞 提交于 2021-01-20 13:35:13
问题 I got this button in the navigator that shows up when a user is logged in and when the user logs out the button is gone. But now i need to refresh my page before the button removes/appears. Here is my code: Button: <div v-if="ingelogd"> <div class="w-2/12 hidden lg:flex" v-for="(data, index) in allIngelogds" :key="index"> <button @click="uitloggen" class="downloadbtn"> {{ data.uitloggenKnop }} </button> </div> </div> in data:() i return this: ingelogd: false and then i created a mounted()

How to watch prop even if it does not change?

随声附和 提交于 2021-01-20 13:31:31
问题 I have watcher with the same name as a prop. The prop is dynamically set in a parent component on some event. I need something that triggers some function in the child component with property value every time the event is triggered on parent -even if the prop it set is the same. Is there any watcher option or other method of handling such case which would allow me to do that ? What I tried (this is in Post component): watch: { replyClicked: { handler(newVal, oldVal) { console.log(newVal,

YYDS: Webpack Plugin开发

纵然是瞬间 提交于 2021-01-20 09:46:44
  作为一名踏足前端时间不长的小开发必须得聊一聊 webpack ,刚开始接触webpack时第一反应这是啥(⊙_⊙)? 怎么这么复杂,感觉好难呀,算了先不管这些!时间是个好东西呀,随着对 前端工程化 的实践和理解慢慢加深,跟webpack接触越来越多,最终还是被ta折服,不禁高呼一声“ webpack yyds(永远滴神)! ”   去年年中就想写一些关于webpack的文章,由于各种原因耽搁了(主要是觉得对webpack理解还不够,不敢妄自下笔);临近年节,时间也有些了,与其 "摸鱼"不如摸摸webpack,整理一些"年货"分享给需要的xdm!后续会继续写一些【 Webpack】系列文章,xdm监督··· 导读   本文主要通过实现一个 cdn优化 的插件 CdnPluginInject 介绍下 webpack 的插件 plugin 开发的具体流程,中间会涉及到 html-webpack-plugin 插件的使用、 vue/cli3+ 项目中webpack插件的配置以及webpack相关知识点的说明。全文大概2800+字,预计耗时5~10分钟,希望xdm看完有所学、有所思、有所输出! 注意: 文章中实例基于 vue/cli3+ 工程展开! 一、cdn常规使用 index.html: <head> ··· </head> <body> <div id="app"></div>

How can I set the images like the link image below in vuetify?

こ雲淡風輕ζ 提交于 2021-01-20 09:32:05
问题 I want to quantify my v-img like the one you see in the image below. Is there a way to make something like the image you see with vuetify's v-img . <div class="row"> <v-img style="margin:2px" max-height="301" max-width="380" :key="index" v-for="(image, index) in post.userPostImg" :src="$store.state.baseURL + '/news/' + image"> </v-img> </div> 回答1: Create two rows with no-gutters prop, the first one contains one image and the other one contains three columns that conain the 3 images : <v-row