gpt4 book ai didi

javascript - Vue...$ 未定义

转载 作者:行者123 更新时间:2023-12-01 04:00:29 25 4
gpt4 key购买 nike

我现在正在学习 Vue,现在我想调用后端并以 JSON 格式提取数据。我在网上关注了多个 Vue 教程(诚然,它们都来自 Laracast),每个教程都说使用 $.get 向后端发出 get 请求。但是,我收到 $ is undefined 错误。从阅读来看,这似乎可能是因为 $ 是一个 jQuery 属性,但如果是这样的话,为什么这些教程没有提到任何有关导入或设置 jQuery 的内容?执行简单 get 请求的纯 Vue 方式是什么?

HTML:

<html>
<head><title>Tests</title>
</head>
<body>
<div id="app">
<div v-for="item in queue">{{ item }}</div>
</div>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="./app.js"></script>
</body>
</html>

JS文件:

new Vue({
el: '#app',
data: {
queue: [],
interval: null,
},
methods: {
loadData: function () {
$.get('localhost:4567/getQueue', function (response) {
this.queue = response;
}.bind(this));
}
},
ready: function () {
this.loadData();

this.interval = setInterval(function () {
this.loadData();
}.bind(this), 3000);
},

beforeDestroy: function(){
clearInterval(this.interval);
}
});

最佳答案

听起来像是一个仓促编写的教程,添加了 jQuery library在 Vue 库解决你的问题之前或之后;不过,我找到了主要的Vue examples / tutorials足以完全学习 Vue。

我还强烈建议学习 .vue template (Single File Components) 。稍后它对您的架构变得更有值(value),并大大加快开发速度。

如果您对更多 Vue 资源感兴趣 check out this site .

关于javascript - Vue...$ 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42233069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com