1. 自定义元素
<! DOCTYPE html >
< html lang = " en" >
< head> < meta charset = " UTF-8" > < meta http-equiv = " X-UA-Compatible" content = " IE=edge" > < meta name = " viewport" content = " width=device-width, initial-scale=1.0" > < title> Document</ title> < style> .self { color : red; } </ style>
</ head>
< body> < selfElement class = " self" > 这是自定义元素</ selfElement>
</ body>
</ html>
2. 初始Vue
<! DOCTYPE html >
< html lang = " en" > < head> < meta charset = " UTF-8" > < meta http-equiv = " X-UA-Compatible" content = " IE=edge" > < meta name = " viewport" content = " width=device-width, initial-scale=1.0" > < title> Document</ title>
</ head> < body> < div id = " app" > < div> {{msg}}</ div> < div> {{1 + 3}}</ div> < div> {{'i' + ' love' + ' you'}}</ div> </ div> < script src = " ../vue.js" type = " text/javascript" > </ script> < script type = " text/javascript" > var vm = new Vue ( { el : '#app' , data : { msg : 'Hello World,Vue!' } } ) </ script>
</ body> </ html>
3. Vue实例
<! DOCTYPE html >
< html lang = " en" > < head> < meta charset = " UTF-8" > < meta http-equiv = " X-UA-Compatible" content = " IE=edge" > < meta name = " viewport" content = " width=device-width, initial-scale=1.0" > < title> Document</ title> < script src = " ../vue.js" > </ script> < script> </ script>
</ head> < body> < div id = " app" > {{ obj }}</ div> < script> var obj = { name : 'Zhang' , age : 10 } ; Object. freeze ( obj) ; var vm = new Vue ( { el : '#app' , data : { obj : obj, message : 'HelloWorld' , num : 123 } } ) ; console. log ( vm. $el === document. getElementById ( 'app' ) ) ; console. log ( vm. $data) ; vm. $watch ( 'num' , function ( newValue, oldValue ) { alert ( '监听到了' + '新值:' + newValue + ' 旧值:' + oldValue) ; } ) </ script>
</ body> </ html>
4. Vue基础
<! DOCTYPE html >
< html lang = " en" >
< head> < meta charset = " UTF-8" > < meta http-equiv = " X-UA-Compatible" content = " IE=edge" > < meta name = " viewport" content = " width=device-width, initial-scale=1.0" > < title> Document</ title> < script src = " ../vue.js" > </ script> < script> </ script>
</ head>
< body> < div id = " app" > {{ message }} < br> {{ data }} < br> {{ test() }} < br> < hr> < span v-bind: title = " message1" > {{ message1 }} </ span> < br> < span v-bind: [URL]= " url" > {{url}} </ span> < br> < div v-if = " isSeen" > 现在你看到我了</ div> < ul> < li v-for = " item in todos" > {{ item.name + item.age }} </ li> </ ul> </ div> < hr> < hr> < div id = " app1" > < p> {{ message }}</ p> < input v-model = " message" > </ div> < script> var app = new Vue ( { el : '#app' , data : { message : 'HelloWorld' , data : 'beijing' , message1 : '页面加载于' + new Date ( ) . toLocaleString ( ) , isSeen : true , todos : [ { name : 'Zhang' , age : 10 } , { name : 'WAng' , age : 25 } , { name : 'Li' , age : 32 } , ] , url : "我是url" } , methods : { test ( ) { return '通过{{}}调用函数' ; } } } ) ; var app1 = new Vue ( { el : "#app1" , data : { message : 'Hello Vue' , } } ) ; </ script>
</ body>
</ html>