Vue.js

Node.js socket 双向通信

只愿长相守 提交于 2020-12-29 10:56:58
使用场景: 聊天室;大量数据常驻交互; 技术栈: Node.js, Vue.js || 原生JS 服务端代码: const app = require('http' ).createServer() const io = require('socket.io' )(app) app.listen( 8877 ) io.on( 'connection', scoket => { let i = 1 const t = setInterval(()=> { i ++ if (i >= 12 ) { clearInterval(t) } // 服务端往客户端发送消息 scoket.emit('news', { hello: 'world', t: new Date().getTime() }) }, 1000 ) // 服务端监听客户端的消息 scoket.on('receiveEvent', data => { console.log( 'receiveEvent: ' , data) }) }) 客户端代码: -- Vue 例子: <template> <div> <p @click="clientToServer">scoket:</p> <p v- for ="(item,index) in arr" :key="index">{{item}}</p> </div> <

VueJS: Input file selection event not firing upon selecting the same file

元气小坏坏 提交于 2020-12-29 10:09:44
问题 How can we file input detect change on SAME file input in Vue Js <input ref="imageUploader" type="file" @change="uploadImageFile"> 回答1: We can add @click event and then clear the value of the file input <template> .... <input ref="imageUploader" type="file" accept=".jpg, .jpeg" @click="resetImageUploader" @change="uploadImageFile"> .... </template> <script> export default { methods: { resetImageUploader() { this.$refs.imageUploader.value = ''; }, uploadImageFile() { .... } } } </script> 来源:

Vuetify 2 toolbar ans 1 navigation drawer with 1 toolbar above the navigation drawer

非 Y 不嫁゛ 提交于 2020-12-29 09:58:46
问题 I'm trying to achieve something like this : Actually i have this : My problem is that currently I can not put the first toolbar above the navigation drawer. <template> <v-app> <v-toolbar app class="elevation-1"> <span>Toolbar1</span> </v-toolbar> <v-toolbar app class="mt-5 elevation-1" style="top: 16px"> <span>Toolbar2</span> </v-toolbar> <v-navigation-drawer app fixed permanent> <v-toolbar></v-toolbar> <v-toolbar flat> <v-list> <v-list-tile> <v-list-tile-title class="title">Filter</v-list

Vuetify 2 toolbar ans 1 navigation drawer with 1 toolbar above the navigation drawer

浪尽此生 提交于 2020-12-29 09:58:39
问题 I'm trying to achieve something like this : Actually i have this : My problem is that currently I can not put the first toolbar above the navigation drawer. <template> <v-app> <v-toolbar app class="elevation-1"> <span>Toolbar1</span> </v-toolbar> <v-toolbar app class="mt-5 elevation-1" style="top: 16px"> <span>Toolbar2</span> </v-toolbar> <v-navigation-drawer app fixed permanent> <v-toolbar></v-toolbar> <v-toolbar flat> <v-list> <v-list-tile> <v-list-tile-title class="title">Filter</v-list

Eslint state already declared [Vuex]

╄→гoц情女王★ 提交于 2020-12-29 09:10:34
问题 I am running ESLint and I am currently running into the following ESLint error: error 'state' is already declared in the upper scope no-shadow const state = { date: '', show: false }; const getters = { date: state => state.date, show: state => state.show }; const mutations = { updateDate(state, payload) { state.date = payload.date; }, showDatePicker(state) { state.show = true; } }; export default { state, getters, mutations }; What would be the best way to fix this? 回答1: The best way to fix

Vue-cli 3: “command failed: npm install --loglevel error”

柔情痞子 提交于 2020-12-29 09:09:25
问题 Every time I try to create a new project ( vue create my-project ), I get this error: ERROR : command failed: npm install --loglevel error I'm on PC / Windows 10, Vue-cli 3.2.1, Node 8.11.3, Npm 5.6.0. Presets: Babel, ESLint & Prettier, SASS, Vue router, Vuex From the log: 2736 silly saveTree `-- vuex@3.0.1 2737 warn ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself. 2738 verbose stack Error: EINVAL: invalid argument, read Any

Vue-cli 3: “command failed: npm install --loglevel error”

风流意气都作罢 提交于 2020-12-29 09:02:21
问题 Every time I try to create a new project ( vue create my-project ), I get this error: ERROR : command failed: npm install --loglevel error I'm on PC / Windows 10, Vue-cli 3.2.1, Node 8.11.3, Npm 5.6.0. Presets: Babel, ESLint & Prettier, SASS, Vue router, Vuex From the log: 2736 silly saveTree `-- vuex@3.0.1 2737 warn ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself. 2738 verbose stack Error: EINVAL: invalid argument, read Any

What is better in vue.js 2, use v-if or v-show?

我们两清 提交于 2020-12-29 08:49:07
问题 I'm working in a project with vue 2. I need to know in which case the performance is better: Use v-if or v-show?. I have a long list and each item's list has a form hidden that I need show and hide to click a button that has each item list. What is better a toggle class of v-show or add and remove the form with v-if? 回答1: tl;dr Assuming the question is strictly about performance: v-show : expensive initial load, cheap toggling, v-if : cheap initial load, expensive toggling. Evan You provided

vue的理解

非 Y 不嫁゛ 提交于 2020-12-29 07:53:00
vue提供的MVVM框架模式的数据双向绑定,实现了HTML和js的代码分离,提高代码的维护性 vue.js的核心思想包括:数据驱动和组件化思想。 如果没有中间的ViewModel则关系图编程下面所示:通过Ajax通信获得后台数据,那么要将获得数据显示在DOM上,则需要手动操作DOM节点。这是一个繁琐的过程,还很容易出错。 而使用vue.js后则省去手动操作DOM 。在vue.js里面只需要改变数据,Vue.js通过Directives指令去对DOM做封装,当数据发生变化,会通知指令去修改对应的DOM,数据驱动DOM的变化,DOM是数据的一种功能自然的映射。vue.js还会对操作做一些监听(DOM Listener),当我们修改视图的时候,vue.js监听到这些变化,从而改变数据。这样就形成了数据的双向绑定。 实现数据双向绑定的方法: 数据劫持结合发布者-订阅者模式(vue.js)【vue data是如何实现的??】 vue.js采用数据劫持结合发布者-订阅者的方式,通过Object.defineProperty()来劫持各个属性的setter,getter,在数据变动时,发布消息给订阅者,触发相应的监听回调。 具体的来讲,Vue.js通过Directives指令去对DOM做封装,当数据发生变化,会通知指令去修改对应的DOM,数据驱动DOM的变化。vue.js还会对操作做一些监听

深入理解vue的watch

巧了我就是萌 提交于 2020-12-29 07:52:05
深入理解vue的watch vue中的wactch可以监听到data的变化,执行定义的回调,在某些场景是很有用的,本文将深入源码揭开watch额面纱 前言 watch的使用 watch的多种使用方式 传值函数 传值数组 传值字符串 传值对象 传值对象的其他作用 源码分析watch 初始watch 创建Watcher watchWatcher 立即执行的watch 与computed比较 前言 version: v2.5.17-beta.0 阅读本文需读懂vue数据驱动部分 watch的使用 当改变data值,同时会引发副作用时,可以用watch。比如:有一个页面有三个用户行为会触发this.count的改变,当this.count改变,需要重新获取list值,这时候就可以用watch轻松完成 new Vue({ el: '#app', data: { count: 1, list: [] }, watch: { // 不管多少地方改变count,都会执行到这里去改变list的值 count(val) { ajax(val).then(list => { this.list = list; }) } }, methods: { // 点击+1,count + 1,刷新列表 handleClick() { this.count += 1; }, // 点击重置,count = 1