鍍金池/ 問答/ HTML問答
冷咖啡 回答
  1. debouncethrottle是目前用得最廣泛的,具體可見樓上的一堆收藏;
  2. 想要確保邏輯上不會(huì)有同時(shí)提交的請求,npm搜“mutex”也有很多;
  3. 或者我也寫了一個(gè)簡易版的,用下面的函數(shù)包裹點(diǎn)擊回調(diào),如果前一次請求尚未結(jié)束,新請求會(huì)和舊請求一起返回。這樣的話回調(diào)要返回Promise

    const debounceAsync = originalFunction => {
      let currentExcution = null;
      const wrappedFunction = async function () {
        // 1. locked => return lock
        if (currentExcution) return currentExcution;
    
        // 2. released => apply
        currentExcution = originalFunction.apply(this, arguments);
        try {
          return await currentExcution;
        }
        finally {
          currentExcution = null;
        }
      };
      return wrappedFunction;
    };

    用法

    const sleep = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
    
    const debounceAsync_UNIT_TEST = async () => {
      const goodnight = debounceAsync(sleep);
      for (let i = 0; i < 8; i++) {
        goodnight(5000).then(() => console.log(Date()));
        await sleep(500);
      }
      console.warn('Expected output: 8 identical datetime');
    };

    https://segmentfault.com/a/11...

乞許 回答

History API了解一下

https://developer.mozilla.org...

向?yàn)g覽器歷史添加一個(gè)狀態(tài)history.pushState

https://developer.mozilla.org...

款爺 回答
wait for a server to send response headers (and start the response body) before aborting the request.

5秒是響應(yīng)完成5秒還是響應(yīng)開始時(shí)已經(jīng)5秒?
timeout只是接收body前是否超時(shí),開始接收body的那一刻起timeout就不管了。

怣人 回答

給你一個(gè)思路,不知道get沒get你的意思

首先用js對(duì)圖片寬高進(jìn)行縮放,這個(gè)比較容易。

然后用很多種方式可以水平垂直居中;

margin-left: 50%;
margin-top: 50%;
transform: translate(-50%, -50%)

或者在 flex 內(nèi)部

margin:auto

厭遇 回答
  1. 代碼第九行不要使用inin用于判斷一個(gè)對(duì)象有沒有一個(gè)屬性,不能判斷一個(gè)數(shù)組是否包含某個(gè)元素,使用includes代替;
  2. 代碼第10行使用str = str.replace重新給str賦值;
function rot13 (str) {
  var empty = [];
  for (var i = 0; i < str.length; i++) {
    empty.push(str.charCodeAt(i))
  }
  var left = empty.filter(function (x) {return x >= 65 && x <= 77})
  var right = empty.filter(function (y) {return y >= 78 && y <= 90})
  for (var j = 0; j < str.length; j++) {
    if (left.includes(str.charCodeAt(j))) { // 使用includes
      str = str.replace(str[j], String.fromCharCode(str.charCodeAt(j) + 13)) // 重新賦值
    }
  }
  return str
}
鐧簞噯 回答

也可以考慮將父元素設(shè)置為display: table-cell; text-align: center

涼汐 回答

網(wǎng)不行,用瀏覽器訪問github看看能不能訪問
2.9.4版的vue-cli似乎有問題,用2.9.3版的可以正常init
可以運(yùn)行以下命令解決

npm uninstall -g vue-cli
npm install -g vue-cli@2.9.3

如果不想裝2.9.3,可以換一條命令init

vue-init webpack attendance

2.9.4直接運(yùn)行vue XXX的命令似乎都有或多或少的問題


vue-cli 2.9.3使用下面的設(shè)置新建項(xiàng)目,可以正常運(yùn)行npm run dev

圖片描述


你這個(gè)init時(shí)npm安裝依賴報(bào)錯(cuò)了,嘗試使用yarn安裝依賴

帥到炸 回答

不太清楚,你有新的發(fā)現(xiàn)嗎?

createElement()的調(diào)用方式如下:

React.createElement(
  type,
  [props],
  [...children]
)

綁定事件寫在[props]中,例如:

var target = React.createElement('button', {
  onClick: () => { alert('lol') },
}, 'Click me');

ReactDOM.render(
        target,
        document.getElementById('root')
);

DEMO:
https://codepen.io/CodingMonk...

默念 回答

再給你推薦一個(gè)vue的UI庫,element

六扇門 回答

change事件,你input_max 和input_min 都能拿到,不管哪個(gè)input輸入值發(fā)生改變時(shí),你都可以進(jìn)行比較,發(fā)現(xiàn)不合法輸入時(shí),進(jìn)行個(gè)動(dòng)作,提示或者清空什么的都可以

茍活 回答

不一定是頁面上,只要沒有引用到就不會(huì)計(jì)算

墨沫 回答

當(dāng)你還要模糊的時(shí)候,就用redux管理吧。
等你能很好的區(qū)分什么樣的數(shù)據(jù)用redux,什么樣的數(shù)據(jù)用component state時(shí),就可以隨心所欲了。

笨笨噠 回答
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <!-- 引入樣式 -->
  <link rel="stylesheet" >
</head>

<body>
  <div id="app">
    <mt-cell-swipe v-for="item in list" :key="item" title="標(biāo)題文字" :label="item" :right="GetBtn(item)">
    </mt-cell-swipe>
  </div>
</body>
<!-- 先引入 Vue -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- 引入組件庫 -->
<script src="https://unpkg.com/mint-ui/lib/index.js"></script>
<script>
  new Vue({
    el: '#app',
    data() {
      return {
        list: '123456789'.split('')
      }
    },
    methods: {
      GetBtn(item) {
        return [{
          content: 'Delete',
          style: {
            background: 'red',
            color: '#fff'
          },
          handler: () => this.handleClick(item)
        }]
      },
      handleClick: function (item) {
        this.$toast(item)
      }
    }
  })
</script>

</html>
陪我終 回答

你沒注意看文檔,你那個(gè)redirect使用不當(dāng),一般有這么兩種方式:

  • 重定向path
const routes = [
  {
    path:"/HelloWorld",
    component: HelloWorld
  },
  {
    path: "/second",
    component: second
  },
  //默認(rèn)
  {
    path: '/',
    redirect: '/HelloWorld'
  }
]
  • 重定向name
const routes = [
  {
    path:"/HelloWorld",
    name: 'helloworld',
    component: HelloWorld
  },
  {
    path: "/second",
    component: second
  },
  //默認(rèn)
  {
    path: '/',
    redirect: { name: 'helloworld' }
  }
]

參考文檔:https://router.vuejs.org/zh-c...

希望我的回答對(duì)你有所幫助!