Skip to content

Instantly share code, notes, and snippets.

@propella
Created November 21, 2018 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save propella/97af35302e9674475f0855de553c44ad to your computer and use it in GitHub Desktop.
Save propella/97af35302e9674475f0855de553c44ad to your computer and use it in GitHub Desktop.
Vue sample
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<div>Template: {{ message }}</div>
<div v-bind:title="title">Please hover</div>
<div>Condition:
<span v-if="seen">Now you see me</span>
</div>
<ul>
<li v-for="(place, index) in places" v-bind:key="place.id">
{{index}}: {{ place.name }}
</li>
</ul>
<div v-on:click="onClick">Event: {{ time }}</div>
<input v-model="message"/>
<div>Degree: <input v-model="degree"/></div>
<div>Radian: <input v-model="radian"/></div>
<select v-model="yesno">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<img v-bind:src="yesnoImg"/>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
message: 'Dynamic message',
title: 'Hover message',
seen: true,
places: [
{ id: 'tower1', name: '通天閣' },
{ id: 'tower2', name: 'スカイツリー' },
],
time: 'Click me',
degree: 90,
yesno: "yes",
yesnoImg: "",
},
methods: {
onClick: function(e) {
this.time = new Date();
}
},
computed: {
radian: {
get: function() {
return Math.PI * 2 * this.degree / 360
},
set: function(newValue) {
this.degree = 360 * newValue / (Math.PI * 2) ;
}
}
},
created: function() {
this.yesno = "no";
},
watch: {
yesno: async function(newValue, oldValue) {
this.yesnoImg = "";
const response = await fetch(`https://yesno.wtf/api?force=${this.yesno}`);
const json = await response.json();
this.yesnoImg = json.image;
}
},
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment