javascript - Vue 未定义
问题描述
我一直在努力解决这个错误一段时间。我尝试了多种方法,但都没有奏效。我要做的就是让这个简单的组件正常工作。请有人帮忙。:)
<script>
const app = new Vue({
el: "#main",
data: function(){
return {
search: '',
customers: [
{ id: '1', name: 'Something', },
{ id: '2', name: 'Something else', },
{ id: '3', name: 'Something random', },
{ id: '4', name: 'Something crazy', }
]};
},
computed:
{
filteredCustomers:function()
{
var self=this;
return this.customers.filter(function(cust){return cust.name.toLowerCase().indexOf(self.search.toLowerCase())>=0;});
//return this.customers;
}
}
});
</script>
<template>
<div id="main">
Search: <input type="text" v-model="search"/>
<div v-bind:v-for="customer in filteredCustomers">
<span>{{customer.name}}</span>
</div>
</div>
</template>
解决方案
您应该包含 Vue 库。
这样做的一种方法是<script>
按照 Vue文档中的描述使用。
推荐阅读
- gradle - 如何在gradle中组合两个任务
- javascript - 如何在 JS 中使用 Event Loop 构造去抖动函数?
- asp.net - 无法使用 NLog 保存 aspnet-sessionid
- java - 致命异常:java.util.UnknownFormatConversionException Conversion = 'End of String'
- hibernate - 启发式完成:结果状态回滚;
- json - 我无法从 START_OBJECT 令牌中反序列化 `java.lang.String` 的实例
- python - 使用现有数据框中的值的新数据框
- list - 从 Lotus Notes 中读取所有类别
- c# - 允许用户灵活查询数据库但防止 SQL 注入
- docker - golang 应用程序的 Docker 临时图像找不到二进制“没有这样的文件或目录”