いつもお世話になっております。
Vue.jsでVueインスタンスにmethodsを渡す方法で悩んでおります。
エントリーファイル(app.js)
import test from './test.js'; const app = new Vue({ el: '#app', test, methods: { function2: function() { alert('function2') } } });
importされるファイル(test.js)
export default { methods: { function1: function() { alert('function1') } } }
HTML
<div id="app"> <button type="button" @click="function1">aaa</button> <button type="button" @click="function2">aaa</button> </div>
このような形で実装をしているのですが、エントリーファイル(app.js)内に記載したmethod(function2) は、HTMLから実行することができました。
ただ、別ファイルにしてimportしたものを、Vueインスタンスに渡して、 function1
も実行できるようにしたいのですが、下記のエラーが発生してしまい、読み込めていないようなのです。
Property or method "function1" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
このような方法は出来ないものなのでしょうか?
まだ、Vue.js を触り始めたばかりで見当違いの質問をしていたら申し訳ございません。
ご教授頂けますと幸いでございます。
何卒、よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/28 12:53