visual studio code 安装 source code pro

source code pro 是谷歌和adobe联合开发的适用于编程开发时使用的开源字体。

下载

到 github 找到该项目,下载该字体(所有 otf 文件)。

安装

linux 系统下载到 ~/.local/share/fonts 目录,windows 直接右键安装。

使用

在 vscode 中选择菜单 文件->首选项->设置,在 用户设置->文本编辑器->字体->Font Family 中,头部插入 'Source Code Variable', 'Source Code Variable Italic',

Linux下进行微信小程序开发

微信开发者工具本质是nw.js,可以移植到 Linux,但是需要 wine 来编译wxml和wxss的wcc和wcsc。

安装wine

  1. 安装:
sudo apt-get install wine
  1. 检查版本:
wine --version
  1. 检查配置
winecfg

安装wine-binfmt

sudo apt-get install wine-binfmt
sudo update-binfmts --import /usr/share/binfmts/wine

安装微信开发工具

git clone https://github.com/cytle/wechat_web_devtools.git
cd wechat_web_devtools
./bin/wxdt install  # 自动下载最新的nw.js,同时部署目录 ~/.config/微信web开发者工具/

常见问题

ERROR:sandbox_linux.cc(370)] InitializeSandbox() called with multiple threads in process gpu-process.
buffer_manager.cc(488)] [.DisplayCompositor]GL ERROR :GL_INVALID_OPERATION : glBufferData: <- error from previous GL command

上面两个问题,是因为配置中使用了gpu导致的,所以在启动时强制执行不使用gpu就可以正常运行

./bin/wxdt --disable-gpu

使用 phpstorm 开发微信小程序

让 phpstorm 实现代码高亮,代码提示。

代码高亮

  1. 打开配置界面,找到:editorfile types
  2. 找到 Cascading Style Sheet,添加 *.wxss
  3. 找到 HTML,添加 *.wxml

Live Templates

  1. 下载wecharCode.jar 到本地
  2. 在菜单 Fileimport settings 中导入

使用 vuex 的 mapState

在 vue 中:

<template>
  <div>
    {{user.name}}
  </div>
</template>

<script>
import {mapState} from 'vuex';

export default {
  computed: {
    ...mapState({
      user: state => state.user
    })
  }
}
</script>

在 store 中:

export default {
    state: {
        user: {}
    },
}

继续阅读

js删除数组里的某个元素

// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};
// 移除数组中的第二项
array.remove(1);
// 移除数组中的倒数第二项
array.remove(-2);
// 移除数组中的第二项和第三项(从第二项开始,删除2个元素)
array.remove(1,2);
// 移除数组中的最后一项和倒数第二项(数组中的最后两项)
array.remove(-2,-1);

来自 jQuery 之父的 stackoverflow

scss 使用 @font-face 引入 fonticon 字体报错

webpack 内置的路径检索在使用特定方式引入文件时,会出现无法加载字体的问题,例如以下方式:

vue
<style lang="scss" src="./path-to-file.scss"></style>

scss
@font-face {
  font-family: "iconfont";
  src: url('./iconfont/iconfont.eot?t=1501135137439'); /* IE9*/
  src: url('./iconfont/iconfont.eot?t=1501135137439#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('./iconfont/iconfont.woff?t=1501135137439') format('woff'), /* chrome, firefox */
  url('./iconfont/iconfont.ttf?t=1501135137439') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
  url('./iconfont/iconfont.svg?t=1501135137439#iconfont') format('svg'); /* iOS 4.1- */
}

下载的字体

如果是从 iconfont 下载的字体,将字体放到访问根目录下。

比如 laravel 的访问根目录是 /public,在里面创建字体目录,如 static/fonts/iconfont,将字体放在该目录下。

在 scss 文件中将路径改为绝对路径。如上面的例子,则可以写为:

@font-face {
  font-family: "iconfont";
  src: url('/static/fonts/iconfont/iconfont.eot?t=1501135137439'); /* IE9*/
  src: url('/static/fonts/iconfont/iconfont.eot?t=1501135137439#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('/static/fonts/iconfont/iconfont.woff?t=1501135137439') format('woff'), /* chrome, firefox */
  url('/static/fonts/iconfont/iconfont.ttf?t=1501135137439') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
  url('/static/fonts/iconfont/iconfont.svg?t=1501135137439#iconfont') format('svg'); /* iOS 4.1- */
}

其实就是不要 loader 自动寻找文件,而直接输出路径,我们只要事先准备好对应的文件即可。

fontawesome

加载 fontawesome 需要先定义 $fa-font-path 变量,如下:

$fa-font-path: "~font-awesome/fonts";
@import '~font-awesome/scss/font-awesome';