2020年7月

Less中calc(100vh - 64px) === 36vh
在使用less的vue项目中,发现calc(100vh - 64px) === 36vh???,原来是先经过less编译处理...

anything inside brackets in the LESS would be calculated by LESS first. So I had to parse the calc as Escape string for LESS

解决:width: ~"calc(100% - 30px)";,注意::这样就不能加变量了

参考:CSS3 calc() in LESS CSS

设计稿只给了PingFangSC-Bold这种苹果字体,但没给font-weight,该怎么做呢?

100 - Thin
200 - Extra Light (Ultra Light)
300 - Light
400 - Regular (Normal、Book、Roman)
500 - Medium
600 - Semi Bold (Demi Bold)
700 - Bold
800 - Extra Bold (Ultra Bold)
900 - Black (Heavy)
参考:常见设计稿字体对应字重font-weight大小

ajax 异步打开新链接被拦截
主要是不是用户自己点击触发的跳转,会被浏览器拦截,看到网上有把ajax变成同步请求来解决的,还有另一种,就是stackoverflow的通过新打开一个页面,然后在重置href来实现:

const target = window.open("","_blank");
ajax().then((data) => {
    target.location.href = data.url;
})

参考链接:jquery window.open in ajax success being blocked

使用了isomorphic-fetch,IE11仍然报Here is no "fetch" on the window env, you need to polyfill it
使用fetch-polyfill的方法,但是明明使用的是isomorphic-fetch,应该已经是polyfill之后的了啊,后在github/fetch中看到:

For use with webpack, add this package in the entry configuration option before your application entry point: entry: ['whatwg-fetch', ...]
于是在webpack入口同样增加:['isomorphic-fetch', ...],也正常了

参考:IE11无法启动,import-html-entry Here is no "fetch" on the window env, you need to polyfill it

记住一次赋值号引起的bug

做leetcode的第二题时,出现一个莫名奇妙的错误:

代码如下:(测试了一下链表的每个节点的值)

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        if( (l1->val=0 && l1->next==nullptr)) {
            return l2;
        }else if( (l2->val=0 && l2->next==nullptr)) {
            return l1;
        }
        // 测试
        ListNode* temp = l1;
        while(temp !=NULL) {
             cout<<"temp->val: "<<temp->val<<endl;
             temp = temp->next;
        }
        // ...code here
    }
}

样例输入是:[2,4,3],却直接遍历输出了:[0,4,3],查了半天才发现是刚开始的语句就写错了...

记得c的缺陷与陷阱中好像就提过,等号被误用成赋值号,一直没遇到过,这次遇到了,长个记性!