Guest User

Untitled

a guest
Nov 21st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. var vm = new Vue({
  2. el: '#demo',
  3. data: {
  4. firstName: 'Foo',
  5. lastName: 'Bar',
  6. fullName: 'Foo Bar'
  7. },
  8. watch: {
  9. firstName: function (val) {
  10. this.fullName = val + ' ' + this.lastName
  11. },
  12. lastName: function (val) {
  13. this.fullName = this.firstName + ' ' + val
  14. }
  15. }
  16. })
  17.  
  18. var vm = new Vue({
  19. el: '#demo',
  20. data: {
  21. firstName: 'Foo',
  22. lastName: 'Bar'
  23. },
  24. computed: {
  25. fullName: function () {
  26. return this.firstName + ' ' + this.lastName
  27. }
  28. }
  29. })
  30.  
  31. computed: {
  32. val () {
  33. return this.someDataProperty * someOtherVariable
  34. }
  35. }
  36.  
  37. computed: {
  38. val (flag) {
  39. return (flag === 1)
  40. ? this.someDataProperty * someOtherVariable
  41. : this.someDataProperty * 5
  42. }
  43. }
  44.  
  45. watch: {
  46. val (n, o) {
  47. console.log(n, o)
  48. }
  49. }
  50.  
  51. this.$store.state.someProperty.someNestedProperty.someDeeplyNestedProperty
  52.  
  53. computed: {
  54. someDeeplyNestedProperty () {
  55. return this.$store.state.someProperty.someNestedProperty.someDeeplyNestedProperty
  56. }
  57. }
  58.  
  59. watch: {
  60. somethingSelected() {
  61. this.router.push('someOtherRoute')
  62. }
  63. }
  64.  
  65. let app = new Vue({
  66. el: '#app',
  67. data: {
  68. name: ""
  69. }
  70. });
  71.  
  72. watchers: {
  73. "name": function(newValue, oldValue){
  74. if(newValue != oldValue)} {
  75. fetch(url, {method: 'post', body: JSON.stringify({name: this.name})}).then(...);
  76. }
  77. }
  78. }
  79.  
  80. Vue.component('my-comp',{
  81. template: '#my-comp',
  82. props: ['username'],
  83. created() {
  84. this.user = this.username;
  85. },
  86. watch:{
  87. username(val){
  88. this.user = val;
  89. }
  90. },
  91. data(){
  92. return{
  93. user: ''
  94. }
  95. }
  96. });
Add Comment
Please, Sign In to add comment