0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Vue.js のサンプル (button クリック)

Last updated at Posted at 2018-08-16
index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />
<script src="https://unpkg.com/vue@2.6.14"></script>
<title>vue.js ex03</title>
</head>
<body>
<table>
<tr>
<td>
<div id="green">
  <button v-on:click="func01">Green</button>
	&nbsp;
  {{ counter_green }}
</div>
</td>

</tr>
<tr>
<td>
<div id="yellow">
  <button v-on:click="func01">Yellow</button>
	&nbsp;
  {{ counter_yellow }}
</td>
</div>
</tr>
<tr>

<td>
<div id="red">
  <button v-on:click="func01">Red</button>
	&nbsp;
  {{ counter_red }}
</div>
</td>
</tr>
</table>

<p />
<div id="clear">
  <button v-on:click="func01">Clear</button>
</div>

<script src="ex03.js"></script>
<p />
Aug/16/2018<p />
</body>
</html>
ex03.js
// ---------------------------------------------------------------
//	ex03.js
//
//					Aug/18/2018
//
// ---------------------------------------------------------------

green = new Vue({
	el: '#green',
	data: { counter_green: 0 },
	methods: {
	func01: function () { this.counter_green += 1 }
	}
})

yellow = new Vue({
	el: '#yellow',
	data: { counter_yellow: 0},
	methods: {
	func01: function () { this.counter_yellow += 1 }
	}
})

red = new Vue({
	el: '#red',
	data: { counter_red: 0},
	methods: {
	func01: function () { this.counter_red += 1 }
	}
})

new Vue({
	el: '#clear',
	data: {},
	methods: {
	func01: function () {
		 green.counter_green = 0
		 yellow.counter_yellow = 0
		 red.counter_red = 0
		 }
	}
})

// ---------------------------------------------------------------

実行の様子
vue_aug1603.png

次のバージョンで確認しました。

Vue.js v2.6.14
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?