相关疑难解决方法(0)

Vue v-on:单击对组件不起作用

我正在尝试在组件中使用on click指令,但它似乎不起作用.当我点击组件时,当我在控制台中获得"测试点击"时,会发生无关紧要的事情.我没有在控制台中看到任何错误,所以我不知道我做错了什么.

的index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>vuetest</title>
  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

App.vue

<template>
  <div id="app">
    <test v-on:click="testFunction"></test>
  </div>
</template>

<script>
import Test from './components/Test'

export default {
  name: 'app',
  methods: {
    testFunction: function (event) {
      console.log('test clicked')
    }
  },
  components: {
    Test
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

Test.vue(组件)

<template>
  <div>
    click here
  </div>
</template>

<script>
export default {
  name: 'test',
  data () {
    return {
      msg: 'Welcome to Your …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component vuejs2

136
推荐指数
6
解决办法
9万
查看次数

标签 统计

javascript ×1

vue-component ×1

vue.js ×1

vuejs2 ×1