简单教程
提交运行
代码编辑器:
<!DOCTYPE html> <meta charset="utf-8"> <title>Vue 2 范例 - 简单教程(www.twle.cn)</title> <link href="/static/next/css/tryit.css?v=2017082407" rel="stylesheet"/> <script src="/static/lib/vue.js/2.5.9/vue.min.js"></script> <div id="app"> <p>{{ site }}</p> </div> <footer>简单教程,简单编程<br/>Copyright © 简单教程</footer> <script> var vm = new Vue({ el: '#app', data: { name: 'Google', url: 'http://www.google.com' }, computed: { site: { // getter get: function () { return this.name + ' ' + this.url }, // setter set: function (newValue) { var names = newValue.split(' ') this.name = names[0] this.url = names[names.length - 1] } } } }) // 调用 setter, vm.name 和 vm.url 也会被对应更新 vm.site = '简单教程 https://www.twle.cn'; document.write('name: ' + vm.name); document.write('<br>'); document.write('url: ' + vm.url); </script>
运行结果: