javascript - Vue 的 @click 功能在 Firefox 中不起作用,但在 Edge、Chrome 中起作用
问题描述
const main = new Vue({
el: '#main',
data: {
result: "",
responseAvailable: false,
currentOpen: null
},
methods: {
fetchData: function(event) {
this.responseAvailable = false;
fetch("https://restapihost.net/cms", {
"method": "GET",
"headers": {
"Content-Type": 'application/json',
'Authorization': 'Basic cmsdfkKKMNijiweeuiVzdGFwaTpyZXN0YXBp'
}
})
.then(response => {
if(response.ok){
return response.json()
} else{
alert("Server returned " + response.status + " : " + response.statusText);
}
})
.then(response => {
this.result = response.data;
this.responseAvailable = true;
})
.catch(err => {
console.log(err);
});
}
}
});
button {
margin-bottom: 1rem;
}
.content {
}
.hide {
display: none;
}
.show {
display:block;
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Responsive + Encoding Meta Tag -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Stylesheet -->
<link href = "styles.css" rel = "stylesheet">
<!-- Title -->
<title>API Call</title>
</head>
<body>
<div id="main">
<h1>API Call Example</h1>
<button @click="fetchData">Get Index</button>
<div v-if="responseAvailable == true" >
<div name="list">
<div v-for="i in result" class="elem">
<p :data-id="i.id" @click="currentOpen=i.id"><i>{{i.title}} </i></p>
<div v-bind:class="{'hide':true, 'show':(i.id === currentOpen)}" v-bind:id="i.id" v-html="i.content"></div>
</div>
</div>
</div>
</div>
</body>
<!-- Vue and Custom JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
<script src = "scripts.js"></script>
</html>
按钮上的@click 功能(获取索引)在 Firefox 中不起作用。我尝试过其他浏览器,例如 Chrome 等。它们都可以正常工作。Firefox 什么都不做。我已经测试了@click="fetchData"、@click="fetchData(event)"、@click.native="fetchData" 没有任何效果。
谁能解释我的 POS 有什么问题?
解决方案
发现问题。代码没问题,没有问题。Firefox 已终止 JS-Engine。原因我不知道。
推荐阅读
- scala - 如何在 Scala FastParse 中直接检索已解析对象的行号和列号?
- while-loop - 循环重新启动后循环不中断
- xml - Powershell 的 XML 配置文件,存储列表
- c++ - 使用 Regex 解析 cpp 中的字符串并创建映射
- assembly - 如何进行装配时间计算?
- python - 如何将 Spark 数据帧转换为 Pandas 并返回 Kedro?
- spring-boot - 禁用 Springboot 执行器端点 /env 的安全性
- python - 有没有更快的方法来创建一个空数组的元素数组而不使用 for 循环
- firebase - 使用 NoSQL 的 Firebase 函数
- sql - 如何通过将一个表中的 id 与 bigquery 中另一个表中的多个列中的 id 连接来获取记录以获取大表?