• Vue如何直接调用Component里的方法

    有时候,我们需要在另一个A Component里直接调用B Component里的方法,但Vue的Component和我们平常写的JavaScript module不一样,不能简单的通过import后就直接调用,下面是我找到的一种方法,目前测试可用

    AComponent.vue

    <template>
      <div>
        <b-component ref="BComponent"></b-component>
      </div>
    </template>
     
    <script>
    import BComponent from './BComponent'
     
    export default {
      name: 'A',
     
      data () {
      },
     
      components: {
        BComponent
      },
     
      methods: {
        callACompoentFunction () {
          this.$refs.BComponent.sayHi()
        }
      }
    }
    </script>
     
    <style scoped>
    </style>
    

    ...

    READ ALL

  • bz2解压失败

    解压bz2压缩包时提示错误:

    [root@test01 e2e]# tar -jxf test.tar.bz2 
    tar (child): bzip2: Cannot exec: No such file or directory
    tar (child): Error is not recoverable: exiting now
    tar: Child returned status 2
    tar: Error is not recoverable: exiting now
    

    看错误就知道bzip2系统不支持,安装所需的处理包,如CentOS下执行

    ...

    READ ALL

  • 快速查看Linux是32位还是64位

    要快速查看Linux操作系统是32还是64位, 可以快速通过几个命令来判断

    使用arch命令

    [root@test01 Home]# arch
    x86_64
    

    使用uname命令

    [root@test01 Home]# uname -a
    Linux test01 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
    

    也可以这样

    [root@test01 Home]# uname -m
    x86_64
    

    ...

    READ ALL

  • Cannot connect to the Docker daemon

    运行容器时遇到一个错误

    # docker run -p 127.0.0.1:6379:6379 --name some-redis -d redis
    docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
    See 'docker run --help'.
    

    这是因为Docker后台服务没有运行,我使用的时Mac电脑,所以找到Docker程序启动就好。如果你时Linux上运行提示这个可以这么启动容器服务

    ...

    READ ALL

  • Mac提示Insecure world writable

    Mac电脑有时候会在某个命令下打印如下警告

    Insecure world writable dir /Users/username in PATH, mode 040777 when running Ruby commands
    

    这个提醒大意是你的宿主目录只有你自己能写,但往往很多时候有一些第三方程序需要往宿主目录写文件的,你可以直接改一下宿主目录的写权限就能消除这个问题

    chmod go-w /Users/username
    

    当然,这个第三方程序也很有可能是木马

    ...

    READ ALL

  • ES7大招async await

    JavaScript异步编写多了以后会特别不好维护,虽然也有一些第三方库专门解决这个问题,但并没有根本性解决这个问题,ES每一版都在想着怎么解决异步编写,Promise显然未能解决这个问题,于是在ES7推出了async await两个关键字,先来看一下简单的使用

    let wait = () => {
      return new Promise(resolve => {
        setTimeout(() => {
          resolve('wait...')
        }, 1000)
      })
    }
     
    (async () => {
      console.log('start...')
      console.log(await wait())
      console.log('end...')
    })()
     
    // Outputs:
    //  start...
    //  wait...
    //  end...
    

    ...

    READ ALL

  • zsh command not found rvm-prompt

    full

    很多人都因为Oh my zsh比较个性的主题而喜欢安装它,但我在安装后只要拖拽改变命令窗口大小它总是不断打出一行错误代码

    zsh: command not found: rvm-prompt

    虽然不影响实际使用,但看着很不舒服,解决这个问题很简单,只需要把以下代码加入.zshrc文件即可

    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

    ...

    READ ALL

  • 推荐一个JavaScript编码规范

    full

    Airbnb大家都知道是做家庭旅馆的,但它们家的研发团队推出了自己的编码规范,各种使用场景都几乎都列出来了,花半个小时读一读非常值得的

    • Github: https://github.com/airbnb/javascript
    • Airbnb JavaScript Style Guide: http://airbnb.io/javascript/

    大部分团队其实都会制定了自己的规范,或者使用第三方制定的规范,比如目前就比较常用的Standardjs,最方便快捷的方法就是在一个第三方规范基础上修改出符合自己团队的规范。

    ...

    READ ALL

  • 推荐一个浏览器端打zip包的插件

    full

    官方网址: http://stuk.github.io/jszip/

    这个插件使用特别简单,一个简单的例子

    // 创建一个 JSZip 实例,后续操作都需要此实例
    var zip = new JSZip();
     
    // 往Zip文件里添加文本
    // 参数1是文件名
    // 参数2 是文本内容
    zip.file("Hello.txt", "Hello World\n");
     
    // 往Zip文件里添加一个images目录, 并返回一个句柄
    // 后续如果需要往images目录里添加文件都需要使用这个句柄操作
    var img = zip.folder("images");
     
    // 往images目录添加一个图片文件
    img.file("smile.gif", imgData, {base64: true});
     
    // 导出zip文件
    // 这里导出文件用到 FileSaver.js 插件,你可以换成其它的
    zip.generateAsync({type:"blob"});
    .then(function(content) {
      // see FileSaver.js
      saveAs(content, "example.zip");
    });
    

    ...

    READ ALL

  • JavaScript浮点数bug

    之前就有看过JavaScript浮点数bug的相关文章,但没有特别关注,直到最近做一个项目,正好是涉及到浮点运算,看了好几次确认逻辑没有问题以后断点跟踪发现了传说中的浮点数bbug。

    $ node
    > 0.8 - 0.1
    0.7000000000000001
    

    这跟运行环境还没有关系,比如Chrome console下

    > 0.8 - 0.1
    0.7000000000000001
    

    但不是每个浮点书运算都会有这个bug,比如:

    $ node
    > 0.8 - 0.1
    0.7000000000000001
    > 0.9 - 0.8
    0.09999999999999998
    > 1.0 - 0.1
    0.9
    > 1.0 - 0.4
    0.6
    > 0.4 - 0.3
    0.10000000000000003
    > 0.1 + 0.1
    0.2
    > 0.5 + 0.1
    0.6
    >
    

    ...

    READ ALL