udemy-vue-basic
  • Initial page
  • 始める
    • on directive
    • access data, methods
    • v-bind
    • v-on
  • Untitled
  • Vuex で state を管理する
    • Install
    • Vuex とは
    • はじめよう
    • Core Concepts
      • State
      • getter
      • mutations
      • actions
  • View-router
Powered by GitBook
On this page
  1. 始める

access data, methods

Previouson directiveNextv-bind

Last updated 6 years ago

main.js
import Vue from "vue";

new Vue({
  el: "#app",
  data: {
    title: "title"
  },
  methods: {
    changeTitle(event) {
      this.title = event.target.value;
    },
    returnName() { // この関数を呼び出す
      return "/ this is name";
    }
  }
});

index.html
<body>
	<div id="app">
		<input type="text" @input="changeTitle">
		{{ title }}
		{{ returnName() }} 
		<!-- () で読んであげれば自動的に method を呼ぶ -->
	</div>
</body>

this にアクセス

main.js
import Vue from "vue";

new Vue({
  el: "#app",
  data: {
    title: "title"
  },
  methods: {
    changeTitle(event) {
      this.title = event.target.value;
    },
    returnName() {
      return this.title + "test";
    }
  }
});

https://codesandbox.io/s/7mvw9q8yj1
https://codesandbox.io/s/xlqwpvj34z