【发布时间】:2021-01-13 01:24:09
【问题描述】:
假设我有一个像这样的单个文件组件:
<template>
// doesn't matter
</template>
<script>
export default {
data() {
return {
redStates: [
"Isfahaan",
"Qom",
"Tehraan",
"Semnaan",
...
],
};
},
methods: {
colorize(paths) {
paths.forEach((path) => {
if (this.redStates.indexOf(path.getAttribute("class")) !== -1) {
path.setAttribute("class", "red");
}
});
},
},
};
window.onload = () => {
const paths = document.querySelectorAll(".Provinces path");
paths.forEach((path) => {
if (this.redStates.indexOf(path.getAttribute("class")) !== -1) {
path.setAttribute("class", "red");
}
});
};
</script>
<style >
...
</style>
有没有办法在“export default”之外访问方法(在本例中为“colorize”)?(在本例中为“window.onload”事件
【问题讨论】:
标签: javascript vue.js vuejs2 vue-component vuejs3