文章加密

;

2019年10月23日 星期三

require.context, watch 的immediate配合handler-- Vue 开发必须知道的 36 个技巧

https://juejin.im/post/5d9d386fe51d45784d3f8637  Vue 开发必须知道的 36 个技巧

https://www.itread01.com/content/1548038172.html webpack 之 require.context 用法


If you want to use your image as a module, do not forget to bind data to your vuejs component
<template>
  <div id="app">
    <img :src="image" />
  </div>
</template>

<script>
import image from "./assets/logo.png"


export default {
    data: function () {
        return {
            image: image
        }
    }
}
</script>

<style lang="scss">
</style> 
And a shorter version :
<template>
  <div id="app">
    <img :src="require('./assets/logo.png')" />
  </div>
</template>

<script>
export default {
}
</script>

<style lang="scss">
</style> 

require.context
the example below is easy to understand, and it seems like if the modules you want to import are not very much, then writing in "require.context" way is more complicated.
import BaseButton from './BaseButton.vue'
import BaseIcon from './BaseIcon.vue'
import BaseInput from './BaseInput.vue'

export default {
  components: {
    BaseButton,
    BaseIcon,
    BaseInput
  }
}
Just to support relatively little markup in a template:
<BaseInput
  v-model="searchText"
  @keydown.enter="search"
/>
<BaseButton @click="search">
  <BaseIcon name="search"/>
</BaseButton>
Fortunately, if you’re using Webpack (or Vue CLI 3+, which uses Webpack internally), you can use require.context to globally register only these very common base components. Here’s an example of the code you might use to globally import base components in your app’s entry file (e.g. src/main.js):
import Vue from 'vue'
import upperFirst from 'lodash/upperFirst'
import camelCase from 'lodash/camelCase'

const requireComponent = require.context(
  // The relative path of the components folder
  './components',
  // Whether or not to look in subfolders
  false,
  // The regular expression used to match base component filenames
  /Base[A-Z]\w+\.(vue|js)$/
)

requireComponent.keys().forEach(fileName => {
  // Get component config
  const componentConfig = requireComponent(fileName)

  // Get PascalCase name of component
  const componentName = upperFirst(
    camelCase(
      // Gets the file name regardless of folder depth
      fileName
        .split('/')
        .pop()
        .replace(/\.\w+$/, '')
    )
  )


  // Register component globally
  Vue.component(
    componentName,
    // Look for the component options on `.default`, which will
    // exist if the component was exported with `export default`,
    // otherwise fall back to module's root.
    componentConfig.default || componentConfig
  )
})

watch    一般watch最初綁定的時候是不會執行的
的immediate配合handler,將可以取得oldValue與newValue,而且immediate會讓最初綁定時也觸法watch
的deep配合handler,將可以取得oldValue與newValue(不確定),並且會同時監聽他的子層,當子曾有改變時也會觸發他(當然爾,它的消耗大)
https://cythilya.github.io/2017/04/15/vue-watch/  Summer。桑莫。夏天https://blog.csdn.net/Amanda_wmy/article/details/83749560 
vue.js监听属性watch(handler方法immediate属性deep属性)

2019年10月21日 星期一

File API (from javascript)

https://www.html5rocks.com/zh/tutorials/file/dndfiles/

https://blog.johnsonlu.org/upload-file-with-file-api/

https://dwatow.github.io/2019/05-22-file-api/ . download

File API 中包含了幾個比較重要的 interface:
  • File:可以用來讀取硬碟上檔案相關檔案資訊的物件
  • FileList:File 物件的集合
  • Blob:表示檔案內容的物件
  • FileReader:讀取檔案用的物件


downloadFileBase64(fileID: string, imageName: string) {
            FileApi.getFile(fileID).then(fileData => {
                const element = document.createElement('a');
                element.setAttribute('href', `data:image/png;base64,${encodeURIComponent(fileData.file)}`);
                element.setAttribute('download', imageName);
                element.style.display = 'none';
                document.body.appendChild(element);
                element.click();
                document.body.removeChild(element);
            });
        },

2019年10月17日 星期四

docker, drone,webhook, pipeline, k8s

docker

其官網ID:a...e8086, 密碼a..e1..6
https://hub.docker.com/
sign in and download install
結果裝不起來

https://skychang.github.io/2017/01/06/Docker-Docker_for_Windows_10_First/

另一種方式安裝https://blog.yowko.com/homebrew-docker/

http://www.voidcn.com/article/p-sfwzrmph-ew.html  docker 打包 node 项目

https://joshhu.gitbooks.io/dockercommands/content/Containers/DockerRun.html  快速建立你的第一個Docker服務

https://yeasy.gitbooks.io/docker_practice/
https://www.youtube.com/watch?v=k5iwKUZY9tk 前端工程師一定要知道的 Docker 虛擬化容器技巧 (18:34)
https://www.arthurtoday.com/2009/12/host-guest.html .Host OS 和 Guest OS 是什麼 ?

有像git,但是用在打包OS(operation system, 作業系統)

*12招給前端的密技

  1. pull
  2. images (映像檔)
  3. run
  4. ps (看行程)
  5. stop
  6. start
  7. exec (進入容器,與run的差別在run會自動開啟來)
  8. commit (提交image)
  9. tag (修改標籤名稱)
  10. rmi (移除image和tag,remove image的縮寫)
  11. rm (移除容器)
  12. push



Drone


如果你曾經開發過需要經常更新版本的應用程式(如 API Service),每次把寫完的 code push 到 Git 後,通常還需要做以下這些事情:
  1. 將修改後的 Release 版本打包完成
  2. 連線到 Host VM 並停止原有服務
  3. 覆蓋原有的程式版本
  4. 重新啟動服務
其實一直以來我都是認命的這樣部署我的 Service 的,直到有一天因為專案有臨時的緊急需求,一整天重複做了快十次這樣的流程後,心裡突然有一個聲音告訴我:
John啊,你一定要做自動部署,你如果現在不出來做,連天公伯都不會原諒你!
剛好團隊近期也導入 Docker 做容器服務管理,在尋找了一些資料以及自動部署流程的教學後,便決定使用 Drone 這套服務來搭配之前已經建置在 Docker 上的 Gitea 版本控制系統來建立一套簡易的 Continuous Delivery 流程。













理想中的自動部署流程,大概是 Push 完 code 就可以泡咖啡等結果的概念。

為什麼選擇Drone?

  • 佔用記憶體資源少(僅約20MB)
  • 所有建置環境皆在 Docker 上實作,避免與系統互相干擾
  • 有多樣 Plugin 可供串接服務
  • 可與各種版本控制系統快速串接(GitHub、GitLab、Gitea、Gogs、Bitbucket 等)
  • 以簡易撰寫 yaml 檔案的方式定義部署流程
以下會詳細介紹從安裝 Docker 到將 Drone 執行為 Docker Container 提供未來部署使用的流程。
(提醒:以下的安裝步驟皆為在 Ubuntu Server 16.04 LTS 環境下安裝,若你的 OS 為 Windows 或 macOS,請參考 Docker 官方文件說明完成安裝。)


https://medium.com/asiayo-engineering/%E7%94%A8-drone-%E6%89%93%E9%80%A0-ci-cd-flow-36b9d14c7620  用 Drone 打造 CI/CD flow

ref:https://medium.com/@stu60610/%E4%BD%BF%E7%94%A8-docker-drone-%E5%BB%BA%E7%AB%8B%E7%B0%A1%E6%98%93%E8%87%AA%E5%8B%95%E9%83%A8%E7%BD%B2%E6%B5%81%E7%A8%8B-part1-a180eb48ff37


webhook

https://ithelp.ithome.com.tw/articles/10193212   第四天:認識 Webhook
Webhook 是讓一個網站能訂閱另一個網站的方法
*上面那篇介紹了實際上是介紹了rails做後端與資料庫,有用到

  • postman
  • imgur

   學會怎麼把圖檔弄到 imgur

  def get_weather_from_cwb
    uri = URI('http://www.cwb.gov.tw/V7/js/HDRadar_1000_n_val.js')
    response = Net::HTTP.get(uri)
    start_index = response.index('","') + 3
    end_index = response.index('"),') - 1
    "http://www.cwb.gov.tw" + response[start_index..end_index]
  end

把氣象圖丟上imgur(那為什麼不是我們自己保存圖片就好呢?因為存圖片要占空間跟頻寬,所以我選擇用 imgur 的空間放圖。imgur 有一個蠻好的地方是,你可以直接把圖片網址給他,他就會幫你備份圖片了,所以我們不用真的把圖檔抓回來再上傳到 imgur。而且作者當時的氣象圖網址是http開頭,而line要求https,imgur提供的是https,現在的話氣象局已經改成https)

  def upload_to_imgur(image_url)
    url = URI("https://api.imgur.com/3/image")
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    request = Net::HTTP::Post.new(url)
    request["authorization"] = 'Client-ID be2d83405627ab8'

    request.set_form_data({"image" => image_url})
    response = http.request(request)
    json = JSON.parse(response.read_body)
    begin
      json['data']['link'].gsub("http:","https:")
    rescue
      nil
    end
end

pipeline
https://docs.drone.io/configure/pipeline/

k8s
not clear

how add class active for parent when child router link clicked

在router parent寫 redirect : { name : 'childName' } ,接著router在想要active by click child's parent view button 寫:to="{name:`parent`}"

2019年10月15日 星期二

TypeScript with querySelector issues,超詭異標準符號!成為新寫法

this.$el.querySelector('.message-bubble__list:last-child')!.scrollIntoView(false);

如果沒有!
會出現Object is possibly 'null'.
!表示必定存在

2019年9月25日 星期三

Base64 vs Binary

Base64 converts your data to an ASCII representation of the binary data. It allows you to embed your data in text streams such as JSON for example. Base64 increases the size of the data transferred by 33%.
multipart/form-data is the standard way of transferring binary data in HTTP requests. It allows you to use specific encodings / content types for each part you'd like to transfer. In my opinion, you should stick to multipart uploads unless you have specific requirements or device/SDK capabilities.