Promise

Promise.reject 失败的回调

https://blog.csdn.net/qq_37939251/article/details/93650542

  1. function getStr1() {
  2. return new Promise(function (resolve, reject) {
  3. setTimeout(function () {
  4. resolve('我');
  5. }, 1000);
  6. });
  7. }
  8. function getStr2() {
  9. return new Promise(function (resolve, reject) {
  10. setTimeout(function () {
  11. resolve('爱');
  12. }, 1000);
  13. });
  14. }
  15. function getStr3() {
  16. return new Promise(function (resolve, reject) {
  17. setTimeout(function () {
  18. resolve('米');
  19. }, 1000);
  20. });
  21. }
  22. function getStr4() {
  23. return new Promise(function (resolve, reject) {
  24. setTimeout(function () {
  25. resolve('饭');
  26. }, 1000);
  27. });
  28. }
  29. getStr1().then(function (data) {
  30. console.log(data);
  31. return getStr2();
  32. }).then(function (data) {
  33. console.log(data);
  34. return getStr3();
  35. }).then(function (data) {
  36. console.log(data);
  37. return getStr4();
  38. }).then(function (data) {
  39. console.log(data);
  40. })

prototype

Vue.prototype.$appName = ‘My App’

https://cn.vuejs.org/v2/cookbook/adding-instance-properties.html

main.js

  1. Vue.prototype.msgSuccess = function(msg) {
  2. this.$message({
  3. showClose: true,
  4. message: msg,
  5. type: "success"
  6. });
  7. }

demo.vue

  1. this.msgSuccess("删除成功");