* Vue version is 1.0
vue cycle data repeatedly resolved
v-for specify, when recycling data, repeated data will be deleted,
vue1.0: As long as you addtrack-by=“$index” <li v-for=’value in arr’ track-ty=’$index’></li>
vue2.0+: You need to get Index on V-FOR, for example: <li V-FOR = ‘(Value, Index) in Arr’ Track-TY = ‘Index’> </li>
vue loaded to avoid users see {{}} Flower brackets
1> Vue1.0 use V-Cloak, where the boners are used
Definition in
css:[v-cloak]{display:none;}, add <div ID = ‘Box’ V-Cloak> {to the node{msg}}</div>
2> Use the V-TEXT instruction to replace {{text}} Flower bracket
3> Use V-HTML instructions to replace {{
{html}}} The righteousness of the righteousness
Vue custom filter
vue1.0 provides its own filter, Limitby, Orderby, etc., custom filter syntax in Vue:
Vue.filter(name,function(input){ return xxx; });
For example:
<script src="lib/vue2.0.js"></script> </head> <body> <div id="box"> { {a|toDou}} </div> </body> <script> Vue.filter('toDou',function (input) { return input<10?'0'+input:''+input; }) var vm=new Vue({ data:{ a:9 }, methods:{ } }).$mount('#box'); </script>
vue two -way filter
<script src="lib/vue.js"></script> <script> //<h2>welcome</h2> Vue.filter('filterHtml',{ read:function(input){ //model-view return input.replace(/<[^<]+>/g,''); }, write:function(val){ //view -> model console.log(val); return val; } }); window.οnlοad=function(){ var vm=new Vue({ data:{ msg:'<strong>welcome</strong>' } }).$mount('#box'); }; </script> </head> <body> <div id="box"> <input type="text" v-model="msg | filterHtml"> <br> { { {msg}}} // Export HTML to </div> The results of the
output are: welcome
Supervision data changes
vm. $ Watch (name, fncb); // shallow degree
<script > var vm = new Vue({ data:{ a:111, b:22 } }).$mount('#box'); vm.$watch('a',function () { this.a = this.a+1; }); document.onclick = function () { vm.a = 1; }; </script>
vm. $ Watch (name, fncb, {deep: true}); // In -depth monitoring, the attribute changes can be heard
Window.#nlοAd = Function () { var vm = new vue ({ EL: '#Box', Data: { json: {name: 'strive', Age: 16}, B: 2 } }); vm. $ watch ('json', function () { alert ('The change has changed'); }, {Deep: true}); document.lnClight = Function () { vm.json.name = 'AAA'; }; };