Skip to content

Instantly share code, notes, and snippets.

window.history.pushState(null, null, "#");
window.addEventListener("hashchange", e=> {
console.log('Hash 更改後觸發');
});
window.addEventListener("popstate", e=> {
window.location.replace('https://medium.com/@Mike_Cheng1208');
});
@MikeCheng1208
MikeCheng1208 / webpack.config.js
Last active January 30, 2019 10:27
圖片+ file-loader
// webpack.config.js
{
test: /\.(jpe?g|png|gif)$/,
use: [{
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
}]
}
@MikeCheng1208
MikeCheng1208 / ui.vue
Created January 24, 2019 02:15
element-ui demo
<script>
export default {
data () {
return {
input: "",
num: 1
}
},
methods: {
handleChange(value) {
@MikeCheng1208
MikeCheng1208 / ToLowerCase2.js
Last active January 21, 2019 10:45
註解版本
const toLowerCase = function(str) {
let strarr = str.split(""); // 先把傳入的字串變成陣列
let samtLetterArr = []; // 轉換後的陣列
let samtLetter = ""; // 最後回傳的字串
// 跑回圈去轉換
strarr.forEach(el => {
let unicode = el.charCodeAt(0); // 一個個把字串轉成 Unicode
let letter = String.fromCharCode(unicode); // 把 Unicode 轉回來字串,塞入 letter
if(unicode <= 90 && unicode >=65){ // 但是如果 Unicode 是需要轉換的話
@MikeCheng1208
MikeCheng1208 / ToLowerCase.js
Created January 21, 2019 07:54
Unicode 大小寫轉換
/**
* @param {string} str
* @return {string}
*/
const toLowerCase = function(str) {
let strarr = str.split("");
let samtLetterArr = [];
let samtLetter = "";
strarr.forEach(el => {
let unicode = el.charCodeAt(0);
@MikeCheng1208
MikeCheng1208 / apidemo2.js
Last active January 18, 2019 05:32
Async / Await api
import { apiArticleItem, apiSearchType } from "api.js";
async function getData() {
try {
const item = await apiArticleItem();
const type = await apiSearchType();
retrun {item, type}
} catch (err) {
console.error(err);
}
@MikeCheng1208
MikeCheng1208 / apidemo.js
Last active January 18, 2019 05:22
api demo2
//引入api.js 可以確保你網站的來源都是同一個進入點
import { apiUserLogin, apiUserLogout, apiUserSignUp } from "api.js";
apiUserLogin({
email: "mike@gmail.com",
password: "123456789"
})
.then(res=> {
console.log(res);
})
@MikeCheng1208
MikeCheng1208 / api.js
Last active January 18, 2019 23:34
axios demo
import axios from 'axios';
// User相關的 api
const userRequest = axios.create({
baseURL: 'https://api/user/'
});
// 文章相關的 api
const articleRequest = axios.create({
baseURL: 'https://api/article/'
});
@MikeCheng1208
MikeCheng1208 / webpack.config.js
Created November 28, 2018 05:22
簡單的entry跟output設定
entry: {
index: './js/index.js',
about: './js/about.js'
},
output: {
path: path.resolve(__dirname, "./dist"),
filename: './js/[name].js',
},
{
test: /\.(sass|scss)$/,
use: [
'vue-style-loader',
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options:{
data: `@import "./src/scss/global/_mixin.scss";`