在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 在Vue源碼中,為什么在Vue上掛載了兩個相同的方法卻都能執(zhí)行?

在Vue源碼中,為什么在Vue上掛載了兩個相同的方法卻都能執(zhí)行?

entry-runtime-with-compiler.js內(nèi)

const mount = Vue.prototype.$mount
Vue.prototype.$mount = function (
  el?: string | Element,
  hydrating?: boolean
): Component {
  el = el && query(el)
  /* istanbul ignore if */
  if (el === document.body || el === document.documentElement) {
    process.env.NODE_ENV !== 'production' && warn(
      `Do not mount Vue to <html> or <body> - mount to normal elements instead.`
    )
    return this
  }
//太長了貼一部分

/runtime/index.js

Vue.prototype.$mount = function (
  el?: string | Element,
  hydrating?: boolean
): Component {
  el = el && inBrowser ? query(el) : undefined
  return mountComponent(this, el, hydrating)
}

然后我自己新建幾個js試了下為什么不行呢
test.js

function va(){}
export {va}

test1.js

import {va} from './test.js'
va.prototype.hei = function(){
    alert(1)
    console.log(1)
}

test2.js

import {va} from './test.js'
const ob = va.prototype.hei
va.prototype.hei = function(){
    alert(2)
    console.log(2)
}

test3.js

import {va} from './test.js'
var a = new va();
a.hei()

最后只alert2,打印了2
ps:我為了保持相似所以建了好幾個..但是為什么不行呢

回答
編輯回答
遺莣

你最后一次修改的va.prototype.hei是啥你調(diào)用到的就是啥啊,跟你引入的順序有關(guān)系。

2017年10月6日 12:26
編輯回答
無標題

源碼中const mount = Vue.prototype.$mount
結(jié)尾又重新調(diào)用 所以執(zhí)行了兩次

2017年9月14日 15:06