A Pen by Peter Chen on CodePen.
Created
October 17, 2018 13:17
-
-
Save peterhpchen/4f6aff0061f31a7052e4852c5790ab38 to your computer and use it in GitHub Desktop.
First Vue
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
<div id="app"> | |
<p>{{message}}</p> | |
<button v-on:click="getRemoteMessage">Inside Button</button> | |
</div> | |
<button onclick="clickButton()">Outside Button</button> |
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
var vm = new Vue({ | |
el: '#app', | |
data: { | |
message: "This is local data.", | |
}, | |
methods: { | |
getRemoteMessage() { // 2. trigger event in Vue instance | |
Promise.resolve("Get remote data by inside button.") // 3. Get data asynchronously | |
.then((res) => { // 4. Return result | |
this.message = res; // 5. Change View Model | |
}); | |
}, | |
}, | |
}); | |
function clickButton() { // 2. trigger event in Vue instance | |
Promise.resolve("Get remote data by outside button.") // 3. Get data asynchronously | |
.then((res) => { // 4. Return result | |
vm.message = res; // 5. Change View Model | |
}); | |
} |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment