標籤:vue his log edit app pre false let property
<!DOCTYPE html><html><head> <meta charset="UTF-8"></head><body> <div id="app"> <textarea v-model="input"></textarea> <button @click="submit">submit</button> <div contenteditable="true"> <pre v-for="item in items"> protected {{ item.type }} _{{ item.name }}; public {{ item.type }} {{ item.name }} { get { return this._{{ item.name }}; } set { SetField(ref this._{{ item.name }}, value); } } </pre> </div> </div> <script src="http://cdn.bootcss.com/vue/2.1.6/vue.min.js"></script> <script> new Vue({ el: ‘#app‘, data() { return { items: [], input: null, } }, methods: { submit() { let lines = this.input .split(/\n/) .map(t => t.trim().split(‘ ‘)) .filter(t => t.length > 6) this.items = [] lines.forEach(arr => { this.items.push({ name: arr[2], type: arr[1], }) }) } } }) </script></body></html>
#region INotifyPropertyChangedprotected void OnPropertyChanged(PropertyChangedEventArgs e){ PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, e);}public event PropertyChangedEventHandler PropertyChanged;protected void OnPropertyChanged([CallerMemberName] string propertyName = null){ //C# 6 null-safe operator. No need to check for event listeners //If there are no listeners, this will be a noop PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}// C# 5 - CallMemberName means we don‘t need to pass the property‘s nameprotected bool SetField<T>(ref T field, T value,[CallerMemberName] string propertyName = null){ if (EqualityComparer<T>.Default.Equals(field, value)) return false; field = value; OnPropertyChanged(propertyName); return true;}#endregion
c# INotifyPropertyChanged