Created
March 20, 2017 19:16
Star
You must be signed in to star a gist
vue js (2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<title>vue</title> | |
<script src="js/vendor/vue.js"></script> | |
</head> | |
<body> | |
<div id="foo"> | |
<p>{{ greetingsSaturn }}</p> | |
<button v-on:click="setGreetings()">set greeting</button> | |
</div> | |
<script> | |
var foo = new Vue({ | |
el: '#foo', | |
data: { | |
greetings: 'Hello World!' | |
}, | |
computed: { | |
greetingsSaturn: function() { | |
return this.greetings.replace('World', 'Saturn').toUpperCase(); | |
} | |
}, | |
methods: { | |
setGreetings: function() { | |
this.greetings = 'By World!'; | |
} | |
}, | |
watch: { | |
greetings: function(newVal) { | |
var xhr = new XMLHttpRequest(); | |
var self = this; | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
self.greetings = JSON.parse(xhr.responseText).data; | |
} | |
}; | |
xhr.open('GET', 'bar.json', true); | |
xhr.send(); | |
} | |
}, | |
mounted: function() { | |
console.log('todo listo'); | |
}, | |
updated: function() { | |
console.log('cambiado!') | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment