存档4月 2020

WebRtc

https://appr.tc/

WebRTC adapter.js
github地址为:https://github.com/webrtc/adapter.
FYI: http://www.vue5.com/webrtc/webrtc.html
主要功能是隐藏像webkitRTCPeerConnection和mozRTCPeerConnection这样的前缀差异,并提供函数将MediaStream附加到HTML的或元素。
– 直接在代码中加入https://webrtc.github.io/adapter/adapter-latest.js
– npm install webrtc-adapter
使用时在JavaScript文件中加入一个模块
const adapter = require(‘webrtc-adapter’);
加载完成后既可以使用,例如可使用
console.log(adapter.browserDetails.browser);
or
import adapter from ‘webrtc-adapter’;
“child_process”: “^1.0.2”,
“fs”: “0.0.1-security”,
“webrtc-adapter”: “^7.5.1”,
“window”: “^4.2.7”
“net”: “^1.0.2”,
“tls”: “0.0.1”,

vue socket.io的github地址:https://github.com/MetinSeylan/Vue-Socket.io

npm install vue-socket.io --save
npm install socket.io-client --save

chrome里无法正常触发vue-socket.io中的connect回调,vue-socket.io使用到了大量es6的语法,考虑到原生es6在浏览器中的兼容性,导入babel-loader(nuxt cli中没有自带),
{src: ‘@/plugins/vue-socket.io’, ssr: false}

webSocket连接的地址是固定的

在main.js中直接这样写
    Vue.use(new VueSocketIO({
      debug: true,
      connection: 'socket地址:端口号',
      vuex: {       // 不需要用到vuex这个可以不加
            store,
            actionPrefix: 'SOCKET_',
            mutationPrefix: 'SOCKET_'
      }
}))

socket可以与vuex结合使用

import store from'./yourstore'
Vue.use(VueSocketio,socketio('http://socketserver.com:1923'), store);

socket地址是静态的写法

mounted(){
this.$socket.emit('connect', 1)
}

npm install –save-dev @gauseen/nuxt-proxy
// nuxt.config.js

modules: [
// 请求代理配置,解决跨域
‘@gauseen/nuxt-proxy’,
],
proxyTable: {
‘/api’: { target: ‘http://example.com’, ws: false }
},
注:
/api ———————— 每个接口特定标识字段 [String]
target —————— 目标代理服务 [String]
ws —————————— 是否支持 websocket 代理 [Boolean]

Nuxt.js

基于Vue2,支持Vue Router,Vuex,Vue Server Renderer(spa),Vue-meta

https://zh.nuxtjs.org/
https://www.nuxtjs.cn/

1,模版安装
https://github.com/nuxt-community/koa-template
vue init nuxt-community/koa-template <project-name>
cd <project-name> # move to your project
需将nuxt降级到1.4.2
npm install # or yarn install*[see note below]

npm i eslint-plugin-html@^3

2.脚手架安装
npm install -g npx
(npx在NPM版本5.2.0默认安装了):
$ npx create-nuxt-app <项目名>

rendering mode :Universal ->否开启SSR服务端渲染

$ cd <project-name>
$ npm run dev 运行开发模式

npm run build 打包构建
npm start 正式运行

npm install --update-binary 重新编译

问题一:使用ES6的 import/export,不支持import需使用babel

解决方案:
    1 在启动参数中加上  --exec babel-node
    2 在根目录下增加.babelrc配制文件
    {
        "presets":["es2015"]
    }
    3 npm install babel-preset-es2015
    npm install babel-cli -S

    deprecated babel-preset-es2015@6.24.1: ????  Thanks for using Babel: we recommend using babel-preset-env now: please read https://babeljs.io/env to update!
+ babel-preset-es2015@6.24.1
failed to start process, "babel-node" exec not found

Module build failed:Error:Plugin/Preset files are not allowed to export objects
1 删除    npm uninstall –save babel-loader
npm uninstall –save @babel/core
    2 新安装    npm install –save -dev babel-loader@^7

问题二:安装 sass

安装依赖
 "fibers": "^4.0.2","sass": "^1.26.3"
Windows + OS X instructions here: https://github.com/nodejs/node-gyp
Ubuntu users please run: `sudo apt-get install g++ build-essential`
RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'`
Alpine users please run: `sudo apk add python make g++`
OS
xcode-select --install
后出现错误
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
解决办法:
1.使用softwareupdate --list查看可用的内容,然后softwareupdate --install -a安装所有更新或softwareupdate --install <product name>只安装Xcode更新。

2.$ rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install

3. Apple 官网下载最新版本的Command Line Tools安装即可
https://developer.apple.com/download/more/
通过brew config查看当前CLT版本号是否变更
CLT: 1103.0.32.62 -> 11.5.0.0.1.1588476445
Xcode: 11.4


npm install  sass fibers

This relative module was not found:
** npm install sass-loader node-sass**
安装后可以会有提示:
npm WARN acorn-jsx@5.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-vue@4.7.1 requires a peer of eslint@^3.18.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.

此时,需要安装:
$ npm i eslint@^3.18.0
$ npm i acorn@^6.0.0
3. 修改 nuxt.config.js
css: [
    'element-ui/lib/theme-chalk/reset.css',
    'element-ui/lib/theme-chalk/index.css'
],
...
build: {
    /*
    ** You can extend webpack config here
    */
    extend(config, ctx) {
      // Run ESLint on save
      if (ctx.isDev && ctx.isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    },
    cache: true
}

配置sass编译 lang="scss"
yarn add @nuxtjs/style-resources node-sass sass-loader
nuxt.config.js文件添加代码
   modules: [
        '@nuxtjs/style-resources'
    ],

Module build failed (from ./node_modules/eslint-loader/index.js): friendly-errors 23:51:12
TypeError: Cannot read property ‘eslint’ of undefined
at Object.module.exports (/Users/sweet/Desktop/IDEA_project/vue/nuxt/node_modules/eslint-loader/index.js:148:18)

解决方案:
1     npm install eslint-loader@2.1.2 –save -dev
最后再次执行就没问题了。
初始化的版本太旧,升级
“backpack-core”: “^0.8.4”,
“eslint”: “^3.19.0”,
“eslint-config-standard”: “^10.2.1”,
“eslint-loader”: “^2.1.1”,

常用组件

npm i koa-router
npm install --save axios
npm i -g webpack webpack-cli

数据渲染

 async mounted() {
      // mounted在服务端渲染时不会被执行,页面源码不会渲染有数据,只会在浏览器中发生效果
      // let self = this
      // let {status, data: { list }} = await axios.get('/city/list')
      // if (status === 200) {
      //   self.list = list
      // }
    },
    async asyncData() {
      let {status, data: { list }} = await axios.get('http://localhost:3000/city/list')
      if (status === 200) {
        return { list }
      }
    }

fetch 用于vuex

报错Error:Interface ‘NuxtApp’ incorrectly extends interface ‘Vue’

https://github.com/nuxt/typescript/issues/49 类似,element-ui的$loading和nuxt.js 中的$loading冲突导致,临时解决方法

tsconfig.json
"compilerOptions": {
    "skipLibCheck": true
}

配置请求的baseUrl参数

    nuxt.config.js文件添加代码
   env: {
        baseUrl: process.env.NODE_ENV == 'development' ? 'http://localhost:3000/mapi' : 'http://www.ddd.cn'
    }
    测试 test.js 文件
    任何文件都可以使用 process.env.baseUrl
import Http from '@/plugins/http/index'; // 封装axios请求
let API = process.env.baseUrl;
     // 文章列表
    getArticleList(params = {}) {
        let url = `${API}/api/article/weblist`;
        return Http.get(url, params)
    },

Window 或 Document 对象未定义?

npm install --save window
那个js文件有window就在那个文件添加一下代码
// 客户端
if (process.client) {
...your code
}
// 浏览器
if (process.browser) {
...your code
}
例子: 以wowjs为例子
if (process.browser) {
var { WOW } = require("wowjs");
}
if (process.browser) {
let wow = new WOW({
live: false
});
wow.init();
}
or
在webpack.base.config.js下的output中添加一条globalObject: 'this'
or
(function(window) {
/* Keep source code the same */
// })(typeof window == "undefined" ? global : window);
// or
})(this);
nuxt.js.config
plugins: [
'@/plugins/element-ui',
// '@/plugins/adapter-latest',
{src: '@/plugins/adapter-latest', ssr: false}
],

koa-redis

安装session和redis
npm i koa-generic-session koa-redis

const session = require(‘koa-generic-session’)
const Redis = require(‘koa-redis’)

app.keys=[‘keys’,’keyskeys’]
app.use(session({
store:new Redis()
}))

Mac下Python环境搭建、多版本管理

通过brew安装pyenv

1)命令行输入:
$ brew install pyenv(如果一直卡在Updating Homebrew就按ctrl+c一次跳转brew update)

2)在home目录的 .bash_profile文件中添加:
vi ~/.bash_profile 在最后增加
eval "$(pyenv init -)"
根据提示需要添加
==> readline
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BSD libedit.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

3)命令行输入,更新一下环境变量:
$ source .bash_profile
注意:没有配置的话无法进行python版本间的切换。

$ pyenv
pyenv 1.2.18
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    列出所有pyenv可用的命令
   exec        Run an executable with the selected Python version
   local       设置或显示本地应用程序特定的Python版本
   global      设置或显示系统全局的Python版本
   shell       设置或显示shell外壳的Python版本
   install     使用python-build安装指定Python版本
   uninstall   卸载已经安装的Python
   rehash      刷新 pyenv shims (安装之后运行这个)
   version     查看当前使用的版本
   versions    列出已经安装的Python版本,当前激活版本用*号标注
   which       显示的完整路径的可执行文件
   whence      列出包含给定的可执行所有的Python版本

使用pyenv安装Python3
1)查看当前激活的是那个版本的Python
pyenv version

2)安装需要的版本:
$ pyenv install 3.7.4 -v (看有哪一些版本可以安装:pyenv install --list)

3)完成后更新数据库:
$ pyenv rehash

4)查看系统已安装的版本:
$ pyenv versions
*号表示系统当前正在使用的版本

5)切换python版本
$ pyenv global 3.6.2
$ pyenv global system

6)确认python版本
python --version

系统全局用系统默认的Python比较好,不建议直接对其操作
pyenv global system
用local进行指定版本切换,一般开发环境使用。
pyenv local 2.7.10
对当前用户的临时设定Python版本,退出后失效
pyenv shell 3.5.0
取消某版本切换
pyenv local 3.5.0 --unset
优先级关系:shell——local——global

删除python
python3版本查看

$ python3 --version
Python 3.7.1
删除Python 3.7 框架:
$ ls /Library/Frameworks/Python.framework/Versions/
3.7
$ sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.7

 删除Python 3.7 应用目录:
$ cd /Applications
$ sudo rm -rf Python\ 3.7/   #Python 3.7存在空格
查看launchpad中python3的IDLE就被删除了

删除/usr/local/bin 目录下指向的Python3.7 的连接:
$ cd /usr/local/bin/
$ ls -l /usr/local/bin
$ rm Python3.7相关的文件和链接 #Python3.7相关的文件和链接需要你自行确认
Python3.7 对应的文件和链接最好删除干净;无法确认的文件和链接就上网搜一下Bing
bin下面要删除这些,防止下次又找
➜ bin rm pydoc3
➜ bin rm pydoc3.7
➜ bin rm python3
➜ bin rm python3-config
➜ bin rm python3.7
➜ bin rm python3.7-config
➜ bin rm python3.7m
➜ bin rm python3.7m-config
➜ bin rm pyvenv
➜ bin rm pyvenv-3.7
➜ bin rm pip3
➜ bin rm pip3.7
➜ bin rm 2to3
➜ bin rm 2to3-3.7
➜ bin rm easy_install-3.7
➜ bin rm idle3
➜ bin rm idle3.7

删除python的环境路径
$ vi ~/.bash_profile
删除Python3.7设置的环境路径。

确认python是否已经删除
$ python3
-bash: python3: command not found

koa

koa-generator

全局安装 npm install koa-generator -g
生成项目 koa2 server /koa2 -e server
Koa的参数
-h, --help 帮助
-V, --version 版本号
-e, --ejs 添加ejs模板引擎支持(默认是jade)
--hbs 添加hbs模板引擎支持(默认是hbs)
-H, --hogan 添加hogan.js支持
-c, --css <engine> 添加css样式 支持 less sass styus css(默认是css)
--git 添加 .gitignore
-f, --force force on non-empty directory

install dependencies:
     $ cd koa2ser && npm install
   run the app:
     $ DEBUG=koa2ser:* npm start

启动项目 npm run dev

koa2-cors
安装npm i koa2-cors –save

css

CSS6:flex布局
https://cloud.tencent.com/developer/article/1354252
http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html
https://segmentfault.com/a/1190000016891326

Vue调试神器vue-devtools

vue-devtools是一款基于chrome游览器的插件,用于调试vue应用,这可以极大地提高我们的调试效率。接下来我们就介绍一下vue-devtools的安装。

chrome商店直接安装
vue-devtools可以从chrome商店直接下载安装,非常简单,这里就不过多介绍了。不过要注意的一点就是,需要翻墙才能下载。

手动安装

第一步:找到vue-devtools的github项目,并将其clone到本地. vue-devtools
git clone https://github.com/vuejs/vue-devtools.git
第二步:安装项目所需要的npm包
npm install //如果太慢的话,可以安装一个cnpm, 然后命令换成 cnpm install
第三步:编译项目文件
npm run build
第四步:添加至chrome游览器
游览器输入地址“chrome://extensions/”进入扩展程序页面,点击“加载已解压的扩展程序…”按钮,选择vue-devtools>shells下的chrome文件夹。

还附上了一个.crx文件,在chrome拓展程序页面上把文件拖进去即可安装。

链接:https://pan.baidu.com/s/139hspAnspD7bJbo81xigmg 密码:1hsv