Code Monkey home page Code Monkey logo

Comments (3)

cobish avatar cobish commented on September 12, 2024

04 月 11 日

Vue

在某个组件的根元素上监听一个原生事件。可以使用 .native 修饰 v-on。例如:

<my-component v-on:click.native="doTheThing"></my-component>

Webpack

今天发现 Webpack 2.0 的 hot reload 特别的慢,发现是前几天加的代码问题(而且经常出现这个提示:Compilation needs an additional pass and will compile again.),去掉了 options 就行了:

修改前:

new webpack.HotModuleReplacementPlugin({
  multiStep: true
})

修改后:

new webpack.HotModuleReplacementPlugin()

from demo.

cobish avatar cobish commented on September 12, 2024

04 月 18 日

Vue

检测数组改动

  • 当利用索引直接赋值时,Vue 是不能检测到该数组的改动,从而没触发状态更新:
this.items[index] = newValue;

为了避免这种情况,以下两种方式都能达到上面的效果,并同时触发状态更新:

// Vue.set
Vue.set(this.items, index, newValue);

// Array.prototype.splice
this.items.splice(index, 1, newValue);

参考来自 Vue 响应式总结

父类 methods 复制到子类

有这么一种情况,封装好的组件里需要写 html 代码,并在里面绑定事件,那么这事件也写在该 Vue 的 methods 下。然而,这些 html 代码是放到组件里去运行的,所以需要将该 Vue 的 methods 复制到组件里。

可以遍历父类的方法,复制给子类:

let methods = {};
Object.keys($parent).forEach(key => {
  const func = $parent[key];
  if (typeof(func) === 'function' && (func.name  === 'boundFn' || func.name === 'n')) {
    methods[key] = func;
  }
});

const component = new Vue({
  methods: methods,
  // ...
});

其中为什么是 func.name === 'boundFn' 还不清楚,而 func.name === 'n' 也是临时解决方法,详细移步 这个 issue

参考来自 iView 的 table 源代码

from demo.

cobish avatar cobish commented on September 12, 2024

04 月 25 日

Js

var isIE = function(ver) {
  var b = document.createElement('b');
  b.innerHTML = '<!--[if IE ' + ver + ']><i></i><![endif]-->';
  return b.getElementsByTagName('i').length === 1;
}

if (isIE(6)) {
  // IE 6
}

if (isIE(9)) {
  // IE 9
}

from demo.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.