Zac*_*Zac 4 javascript components vue.js nuxt.js
再次敲我的头。
我很惊讶我没有在 SOF 上看到类似的问题,但这真的很奇怪。这段代码是有效的,但我移到了一个独立的组件中,以便在多个页面上使用。这是我转到页面时遇到的错误:
handler.call is not a function
我知道这是这个组件,因为如果我从页面中删除该组件,则没有错误并且运行良好。组件不调用函数,脚本中也没有函数。我不知道发生了什么。
在控制台日志中,也没有太多帮助:
TypeError: "handler.call is not a function"
NuxtJS 21
invokeWithErrorHandling
callHook
insert
invokeInsertHook
patch
_update
updateComponent
get
Watcher
mountComponent
$mount
mount
_callee5$
tryCatch
invoke
method
asyncGeneratorStep
_next
run
notify
flush
Run Code Online (Sandbox Code Playgroud)
这是非常简单的组件源代码:
TypeError: "handler.call is not a function"
NuxtJS 21
invokeWithErrorHandling
callHook
insert
invokeInsertHook
patch
_update
updateComponent
get
Watcher
mountComponent
$mount
mount
_callee5$
tryCatch
invoke
method
asyncGeneratorStep
_next
run
notify
flush
Run Code Online (Sandbox Code Playgroud)
这就是我导入组件的方式:
<template>
<div>
<button v-if="can_edit" class='btn-blue'> Edit </button>
<div v-for="card in cards" class='my-credit-card' v-bind:key="card.id">
<h5>{{card.name}}</h5>
<h5 class='mt-0'>•••• •••• •••• {{card.last4}}</h5>
<p class='small'>Exp. {{card.expiration}}</p>
</div>
<div v-if="cards.length == 0">
<p class='subtle'>
Your saved payment methods will display here once you send your first card!
</p>
</div>
<a v-if="(can_add && cards.length > 0)" href="/add-card" class='action'> + Add New Card </a>
</div>
</template>
<script>
export default {
data : function(){
return {
cards : [
{
id: 1,
name: "Lisa Smith",
last4: "4231",
expiration: "12/2022"
},
{
id: 2,
name: "John Smith",
last4: "1234",
expiration: "11/2023"
},
],
};
},
props : {
can_add : {
default : true,
type: Boolean,
},
can_edit : {
default : true,
type: Boolean,
},
},
mounted : {
// fetch cards
},
}
</script>
Run Code Online (Sandbox Code Playgroud)
ski*_*tle 25
这个:
mounted : {
// fetch cards
},
Run Code Online (Sandbox Code Playgroud)
应该:
mounted () {
// fetch cards
},
Run Code Online (Sandbox Code Playgroud)
您将安装的钩子设置为一个对象,该对象上没有call方法。
| 归档时间: |
|
| 查看次数: |
9425 次 |
| 最近记录: |