vLink.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <navigator
  3. :url="url"
  4. :openType="currentOpenType"
  5. :animationDuration="animationDuration"
  6. :hoverClass="hoverClass"
  7. :hoverStopPropagation="hoverStopPropagation"
  8. :hoverStartTime="hoverStartTime"
  9. :hoverStayTime="hoverStayTime"
  10. :target="target"
  11. @click="toNext"
  12. >
  13. <slot></slot>
  14. </navigator>
  15. </template>
  16. <script>
  17. import qs from "qs";
  18. export default {
  19. name: "vLink",
  20. props: {
  21. to: {
  22. default() {
  23. return "";
  24. },
  25. require: true,
  26. type: String | Object,
  27. },
  28. replace: {
  29. defalut: false,
  30. requires: false,
  31. type: Boolean,
  32. },
  33. openType: {
  34. default: "navigate",
  35. require: false,
  36. type: String,
  37. },
  38. animationDuration: {
  39. default: 300,
  40. require: false,
  41. type: Number,
  42. },
  43. hoverClass: {
  44. default: "navigator-hover",
  45. reuqire: false,
  46. type: String,
  47. },
  48. hoverStopPropagation: {
  49. default: false,
  50. reuqire: false,
  51. type: Boolean,
  52. },
  53. hoverStartTime: {
  54. default: 50,
  55. require: false,
  56. type: Number,
  57. },
  58. hoverStayTime: {
  59. default: 600,
  60. require: false,
  61. type: Number,
  62. },
  63. target: {
  64. default: "self",
  65. require: false,
  66. type: String,
  67. },
  68. },
  69. computed: {
  70. currentOpenType() {
  71. if (this.replace) {
  72. return "redirect";
  73. } else {
  74. return this.openType;
  75. }
  76. },
  77. url() {
  78. var url = "",
  79. query;
  80. if (typeof this.to == "string") {
  81. url = this.to;
  82. } else {
  83. url = this.to.path;
  84. query = qs.stringify(this.to.query);
  85. }
  86. return `${url}${url.includes('?') ? '&' : '?'}${query||''}`
  87. },
  88. },
  89. methods: {
  90. toNext(){
  91. this.$navFontColor()
  92. }
  93. },
  94. };
  95. </script>