Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过v-on调用函数内部的函数:单击_Javascript_Function_Methods_Vue.js - Fatal编程技术网

Javascript 通过v-on调用函数内部的函数:单击

Javascript 通过v-on调用函数内部的函数:单击,javascript,function,methods,vue.js,Javascript,Function,Methods,Vue.js,如何在函数内部调用函数 模板:(HTML) 我收到了警告: [Vue warn]:事件“单击”的处理程序无效:未定义 这可以通过JS调用This.hello().world(),但不能像v-on 我缺少什么?我不认为这是一个vue问题 this.hello().world()无效,因为现在无法访问world()。尝试在hello函数的和处添加双括号(): methods: { hello: function() { return { world: function()

如何在函数内部调用函数

模板:(HTML)

我收到了警告:

[Vue warn]:事件“单击”的处理程序无效:未定义

这可以通过JS调用
This.hello().world()
,但不能像
v-on


我缺少什么?

我不认为这是一个vue问题

this.hello().world()
无效,因为现在无法访问
world()
。尝试在
hello
函数的和处添加双括号
()

methods: {
  hello: function() {
    return {
        world: function() {
            alert('hello world');
        }
    }();
  }
}

现在可以像这样访问内部函数:
this.hello.world()

它应该以不同的方式使用,以使其正常工作

<a v-on:click="hello().world()">foo</a>

只需将world定义为方法内部、全局或vue组件中的函数,并以常规方式调用它即可

foo

函数世界(){
警报(“你好世界”);
}
{
方法:{
您好:函数(){
世界();
}
}
}
还是这个

<vue component> {
  methods: {
    hello: function() {
        this.world();
    },
    world: function() {
        alert("Hello world");
    }
  }
}
{
方法:{
您好:函数(){
这个世界();
},
世界:功能(){
警报(“你好世界”);
}
}
}

像这样使用
foo
Yes,答案应该是@BelminBedak Post it!
<a v-on:click="hello().world()">foo</a>
function world() {
  alert("hello world");
}

<vue component> {
  methods: {
    hello: function() {
        world();
    }
  }
}
<vue component> {
  methods: {
    hello: function() {
        this.world();
    },
    world: function() {
        alert("Hello world");
    }
  }
}