之前提問(wèn)并沒(méi)有指出是什么所謂同源事件 故而現(xiàn)在更新一波
其實(shí)也沒(méi)有什么難度,看了你的demo,無(wú)非是一些事件注冊(cè),好消息是我剛才順手寫了個(gè)vue-highchart里使用的例子,先放效果給你看吧
其實(shí),最重要的是你忘記框架或者庫(kù)的存在,一切從js的層面去看它
以下是你評(píng)論里貼的例子的截圖
可以看到就是獲取自身chart對(duì)象以及dom 然后得到其它c(diǎn)hart對(duì)象以及dom 然后開(kāi)始事件注冊(cè)
所以vue里面我們也這樣做不就好了?
<template>
<div>
<highcharts style="height:200px;width:500px;" :options="createOption(chartData.chart1)" ref="c1"></highcharts>
<highcharts style="height:200px;width:500px;" :options="createOption(chartData.chart2)" ref="c2"></highcharts>
<highcharts style="height:200px;width:500px;" :options="createOption(chartData.chart3)" ref="c3"></highcharts>
</div>
</template>
<script>
import { offset } from "@/js/utils";
export default {
name: "test",
data() {
return {
chartData: {
chart1: [["1月", 10], ["2月", 12], ["3月", 22]],
chart2: [["1月", 44], ["2月", 30], ["3月", 22]],
chart3: [["1月", 10], ["2月", 30], ["3月", 8]],
},
};
},
methods: {
createOption(data) {
return {
series: [{ data }],
};
},
},
mounted() {
const { c1, c2, c3 } = this.$refs;
const chart1 = c1.chart;
const chart2 = c2.chart;
const chart3 = c3.chart;
// 你看chart對(duì)象是不是得到了
const allChart = [chart1, chart2, chart3];
// 定義一個(gè)獲取其它兄弟表集合的方法
allChart.getOther = function(one) {
return allChart.filter(c => c !== one);
};
// 循環(huán)進(jìn)行事件綁定
allChart.forEach(chart => {
// 你看自身chart的dom是不是得到了
const container = chart.container;
if (container instanceof Element) {
container.addEventListener("mousemove", function(e) {
var sourceXAxis = chart.xAxis[0];
var extremes = sourceXAxis.getExtremes();
var targetChartContainerList = allChart.getOther(chart);
targetChartContainerList.forEach((ct, index) => {
var targetChart = ct;
var targetDom = ct.container;
var sourceOffset = offset(container);
var targetOffset = offset(targetDom);
var targetE = {};
for (var i in e) {
targetE[i] = e[i];
}
targetE.pageX =
e.pageX + targetOffset.left - sourceOffset.left;
targetE.pageY =
e.pageY + targetOffset.top - sourceOffset.top;
var targetEl =
targetDom.querySelector(
"rect.highcharts-background"
) ||
targetDom.querySelector("path.highcharts-tracker");
targetE.target = targetE.srcElement = targetE.fromElement = targetE.toElement = targetEl;
targetE.delegateTarget = targetE.currentTarget = targetDom;
targetE.originalEvent = targetE;
if (targetChart && targetChart.pointer) {
targetChart.pointer.onContainerMouseMove(targetE);
}
if (targetChart && targetChart.scroller) {
targetChart.scroller.mouseMoveHandler(targetE);
}
if (
chart.mouseIsDown == "mouseup" ||
chart.mouseIsDown == "mousedown"
) {
if (targetChart && targetChart.xAxis[0]) {
var targetXAxis = targetChart.xAxis[0];
targetXAxis.setExtremes(
extremes.min,
extremes.max
);
}
}
});
return false;
});
}
});
},
};
</script>
你看看事件注冊(cè)部分是不是和你的那個(gè)代碼很像,沒(méi)錯(cuò),我就是照著抄的。
至于offset方法是啥?因?yàn)槲彝耆灰蕾囉趈query,所以自己實(shí)現(xiàn)了一個(gè)offset方法,基本也是照著jquery源碼抄著改的
也可以給你看一下offset的代碼
// offset: borrow ideas from the implement of offset in jQuery.fn.extend
export const offset = elem => {
/* jshint eqeqeq: false */
const isWindow = obj => obj != null && obj == obj.window;
const getWindow = ele =>
isWindow(ele)
? ele
: ele.nodeType === 9 ? ele.defaultView || ele.parentWindow : false;
let docElem,
win,
box = { top: 0, left: 0 },
doc = elem && elem.ownerDocument;
if (!doc) {
return;
}
docElem = doc.documentElement;
// Make sure it's not a disconnected DOM node
if (!docElem.contains(elem)) {
return box;
}
// If we don't have gBCR, just use 0,0 rather than error
// BlackBerry 5, iOS 3 (original iPhone)
if (typeof elem.getBoundingClientRect === "function") {
box = elem.getBoundingClientRect();
}
win = getWindow(doc);
return {
top:
box.top +
(win.pageYOffset || docElem.scrollTop) -
(docElem.clientTop || 0),
left:
box.left +
(win.pageXOffset || docElem.scrollLeft) -
(docElem.clientLeft || 0),
};
};
哦對(duì)了,我只抄了mousemove部分,其它部分你自己對(duì)著慢慢抄.
實(shí)際使用的時(shí)候,addEventListener里的function最好不要匿名,這樣方面組件beforeDestory的時(shí)候可以removeEventListener取消監(jiān)聽(tīng)
先排除是不是你代碼里面有這么個(gè)img標(biāo)簽
注釋說(shuō)了在第一次使用的時(shí)候才會(huì)初始化
/**
* The table, initialized on first use, and resized as
* necessary. When allocated, length is always a power of two.
* (We also tolerate length zero in some operations to allow
* bootstrapping mechanics that are currently not needed.)
*/
transient Node<K,V>[] table;
初始化代碼在 final Node<K,V>[] resize() 方法里面,
Node<K,V>[] newTab = (Node<K,V>[])new Node[newCap];
table指向這個(gè)newTab
md5 不是加密 彩虹表破解
前端通過(guò)一定手段把處理過(guò)的密碼傳到后端
后端用一樣的手段將數(shù)據(jù)庫(kù)的密碼處理 然后對(duì)比是否一樣
你需要好好看看這個(gè)函數(shù)的作用了 array_multisort
<?php
$data[] = array('volume' => 67, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 1);
$data[] = array('volume' => 85, 'edition' => 6);
$data[] = array('volume' => 98, 'edition' => 2);
$data[] = array('volume' => 86, 'edition' => 6);
$data[] = array('volume' => 67, 'edition' => 7);
//本例中將把 volume 降序排列,把 edition 升序排列。
//現(xiàn)在有了包含有行的數(shù)組,但是 array_multisort() 需要一個(gè)包含列的數(shù)組,因此用以下代碼來(lái)取得列,然后排序。
// 取得列的列表
foreach ($data as $key => $row) {
$volume[$key] = $row['volume'];
$edition[$key] = $row['edition'];
}
// 將數(shù)據(jù)根據(jù) volume 降序排列,根據(jù) edition 升序排列
// 把 $data 作為最后一個(gè)參數(shù),以通用鍵排序
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
?>
const echarts = require('echarts');
require('echarts-gl');
const KnowledgeOPs = echarts.init(document.getElementById('containerKG'));
這樣寫就不會(huì)報(bào)錯(cuò)了
go-micro微服務(wù)框架,自己編程實(shí)現(xiàn)一個(gè)要好些吧
debounce和throttle是目前用得最廣泛的,具體可見(jiàn)樓上的一堆收藏;或者我也寫了一個(gè)簡(jiǎn)易版的,用下面的函數(shù)包裹點(diǎn)擊回調(diào),如果前一次請(qǐng)求尚未結(jié)束,新請(qǐng)求會(huì)和舊請(qǐng)求一起返回。這樣的話回調(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');
};
find({'value': /^.{0,5}$/, 'key': name})
三元可以嗎?
{item.columns.count?item.columns.count:0}
你這個(gè)能顯示正確嗎?
如果obj是這樣,{columns.count:99},這么寫
{item["columns.count"]?item["columns.count"]:0}你如果是自己直接調(diào)用API的話,你的組件里就會(huì)有很多ajax調(diào)用,組件和action耦合了,個(gè)人看法
走在路上,突然想到了這是什么問(wèn)題。。
var oScript = document.createElement("script");
oScript.src = 'http://suggestion.baidu.com/su?wd=' + this.value + '&cb=solve';
document.body.appendChild(oScript);
script在標(biāo)簽插入DOM中才向baidu請(qǐng)求數(shù)據(jù),請(qǐng)求到數(shù)據(jù),會(huì)調(diào)用solve回調(diào)函數(shù),但當(dāng)前全局作用域中沒(méi)有solve函數(shù),所以會(huì)執(zhí)行失敗。。
首先,高流量場(chǎng)景下,不會(huì)有這種 30 分鐘的東西。
其次,這類 30 分鐘的東西,如果未完成,在設(shè)計(jì)上是會(huì)重跑的。
你應(yīng)該用一個(gè)RadioGroup來(lái)管理RadioButton的選中和取消,而不用點(diǎn)擊事件來(lái)管理,你這樣邏輯非常亂而且擴(kuò)展性很差
array_merge
我寫了一個(gè)demo,在你那上面精簡(jiǎn)了不少,思路就是這樣,你運(yùn)行看看效果:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>example</title>
</head>
<body>
<div id="app">
<div class="total">
<span>總共 {{totalCount}} 道</span>
<span>合計(jì): ¥ {{totalPrice}}</span>
<p>選擇的折扣:<span>{{selectDiscount}}</span></p>
折后金額:<span>{{afterDiscount}}</span>
<p>選擇折扣:</p><span v-for="item in discount" :key="item.id" @click="addDiscount(item)" style="cursor:pointer;"> {{item.name}}</span>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
totalCount: 5,
totalPrice: 155.24,
selectDiscount: null,
discount: [{
id: 1,
name: 0.9
}, {
id: 2,
name: 0.8
}, {
id: 3,
name: 0.7
}, {
id: 4,
name: 0.6
}, {
id: 5,
name: 0.5
}, {
id: 6,
name: 0.4
}]
},
computed: {
afterDiscount() {
return (this.totalPrice * this.selectDiscount).toFixed(2);
}
},
methods: {
addDiscount(item) {
return this.selectDiscount = item.name;
}
}
})
</script>
</body>
</html>commonjs一般在node環(huán)境中
是在這里更改的,1就是1分錢的意思
北大青鳥(niǎo)APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
北大課工場(chǎng)是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國(guó)家深化產(chǎn)教融合/校企合作的政策,積極推進(jìn)“中國(guó)制造2025”,實(shí)現(xiàn)中華民族偉大復(fù)興的升級(jí)產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國(guó)職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開(kāi)發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_(kāi)發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開(kāi)發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開(kāi)發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開(kāi)發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。