下記のように記述すると
ロード時にエラーになり、ボタン2からは「testfunc」を呼び出せますがボタン1からは呼び出せません。
やりたいことはvueオブジェクトに設定したコンポーネントのテンプレート内からクリックをトリガーに「testfunc」を呼び出すことなのですが。
どう書いたらうまくいけるでしょうか。
js
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2<html xmlns="http://www.w3.org/1999/xhtml"> 3<head> 4 5 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script> 6 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue-router/3.0.1/vue-router.js"></script> 7 8 <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 9 <title>さんぷる</title> 10</head> 11 12<body> 13 14 15<section class="container" id="app"> 16 17 <btn1></btn1> 18 <input type="button" @click="testfunc" value="ボタン2"> 19 20</section> 21 22<script type="text/javascript"> 23 24 25var app = new Vue({ 26 el: "#app", 27 methods: { 28 testfunc: function() { 29 alert("ok"); 30 } 31 }, 32 components: {'btn1':{template: '<input type="button" @click="testfunc" value="ボタン1">'}} 33}); 34 35</script> 36 37 38</body> 39</html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/13 03:21
2018/02/13 04:15
2018/02/13 04:45
2018/02/13 05:49 編集