2017

2017.10.30

activated

  • type: Function

  • Details:

called when a kept-alive component is activated.

  • example:
{
  activated () {
    // something you want to do when enter this component.
    this.initData()
  }

  methods: {
    initData () {
      // init this component to do.
    }
  }
}

2017.10.31

async

  • description: when you want to get something with ajax, maybe you can do this way.

  • example:

async function init () {
  // getData is a ajax function
  let res = await getData()
  // or you want to get data
  let data = (await getData()).data
}

2017.11.06

core

if use *, the cookie with the http request will be none.

if use ip, the cookie will be have.

put pictures on another server

why: sometimes, the web sites put pictures and other static files on another server.

Because the browser has a limit on the threads downloading resources under the same domain name, so it's faster to load resources under multiple domians.

let & var & function

function declaration in advance.

var will variable elevation.

let will not variable elevation.

  • example
console.log(a)
var a = 1
// undefined

console.log(b)
let b = 2
// will be error `b is not defined`

console.log(test)
function test () { console.log('test') }
// ƒ test() { console.log('test') }

2017.11.09

some commands in GIT

git branch view this project local branches.

git branch -r view this project remote branches.

git branch -d [name] delete the local branch that name is the name.

git branch -D [name] Forced to delete the local branch that name is the name.

git push origin [name] push the local branch code to the remote branch.

git push origin :[name] delete the remote branch.

when someone else add a new branch, you can't find the new branch with the command git branch -r

now, you can use git remote update to update branch, then you can find the new branch with the command git branch -r

Similarly, when someone else delete a branch, you can't find it too.

now, you can use git remote prune origin to find the branch is deleted.

use command git remote show origin You can check the remote address, remote branch, as well as the corresponding relationship between the local branch and other information.

2017.11.10

the ftp-sync in vscode

{
  "remotePath": "/path/path/", // path
  "host": "", // ip
  "username": "", // root
  "password": "", // your password
  "port": 22, // port
  "secure": false,
  "protocol": "sftp", // sftp
  "uploadOnSave": false,
  "passive": false,
  "debug": false,
  "privateKeyPath": null,
  "passphrase": null,
  "ignore": [
      "\\.vscode",
      "\\.git",
      "\\.DS_Store",
      "\\node_modules"
  ],
  "generatedFiles": {
      "uploadOnSave": false,
      "extensionsToInclude": [],
      "path": ""
  }
}

use shift + ctrl + p

keydown ftp to config or push your file.

2017.11.22

dynamic add js files

let addScript = function (files, index = 0, callback) {
  let baseUrl = './site/'
  let head = document.getElementsByTagName('head')[0]
  let script = document.createElement('script')
  script.type = 'text/javascript'
  script.src = baseUrl + files[index]
  head.appendChild(script)
  script.onload = script.onreadystatechange = function () {
    if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
      script.onload = script.onreadystatechange = null
      if (files.length > index + 1) {
        addScript(files, ++index, callback)
      } else {
        callback()
      }
    }
  }
}

export default function importFile (callback) {
  let files = [
    'src1',
    'src2'
  ]
  addScript(files, 0, callback)
}

2017.11.26

Single line and multi line

css Single line and multi line beyond concealment

/* single line */
.test {
  overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
}
/* muti line */
{
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

2017.11.29

js trigger change event

trigger (elem, event) {
  let evt = document.createEvent('HtmlEvents') // 还有onchange则是HtmlEvents,Events
  evt.initEvent(event, true, true)
  elem.dispatchEvent(evt)
}
trigger(El, 'change')

js get iframe's window

let iframe = document.querySelector('iframe')
iframe.contentWindow

2017.12.05

async with try

when you use async function, you can handle error with try

async function test () {
  try {
    let res = await getTests()
  } catch (err) {
    console.log(err)
  }
}

2017.12.06

Decimal

Binary conversion decimal & Decimal conversion binary

let a = 100
a.toString(2) // "1100100"

parseInt('1100100', 2) // 100

2017.12.07

sort

let a = [5, 3, 7, 1, 15]
a.sort((i, j) => i > j)
console.log(a) // [1, 3, 5, 7, 15]

2017.12.14

export excel

/**
 * tip: responseType: 'blob' !!!
 * @params {Blob} blob
 * @params {String} fileName
 */
function downFile (blob, fileName) {
  if (window.navigator.msSaveOrOpenBlob) {
    navigator.msSaveBlob(blob, fileName)
  } else {
    let link = document.createElement('a')
    link.href = window.URL.createObjectURL(blob)
    link.download = fileName
    link.click()
    window.URL.revokeObjectURL(link.href)
  }
}

2018.01.25

div to middle

<div class="outer">
  <div class="inner"></div>
</div>
/* base */
.outer {
  width: 300px;
  height: 300px;
  background-color: skyblue;
}
.inner {
  width: 100px;
  width: 100px;
  background-color: red;
}
/* way1 */
.inner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
}
/* way2 */
.inner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
/* way3 */
.inner {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -50px;
  margin-left: -50px;
}
/**
 *
 * @param {name} cookie's name
 * @param {value} cookie's value
 * @param {expire} cookie's expire(time)
 * @param {path} 规定 cookie 的服务器路径
 * @param {domain} 规定 cookie 的域名
 * @param {secure} 规定是否需要在安全的 HTTPS 连接来传输 cookie
 */
setcookie(name, value, expire, path, domain, secure)
  • setCookie expire with js
function SetCookie(name,value)
{
    var Days = 30 //此 cookie 将被保存 30 天
    var exp = new Date()
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 *1000)
    document.cookie = name + "="+ escape(value) + ";expires=" + exp.toGMTString()
}