Home.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!-- -->
  2. <template>
  3. <div class="Home" :class="{ last: topImgInd === 8 }">
  4. <!-- 顶部图片 -->
  5. <div class="topImg">
  6. <img :src="require(`@/assets/img/${topImgInd}.png`)" alt="" />
  7. </div>
  8. <!-- 中间内容---使用动态组件 -->
  9. <div class="main" :class="{ mainAc: myMenucShow }">
  10. <keep-alive>
  11. <component
  12. v-if="topImgInd !== 1 && topImgInd !== 8"
  13. :is="`Son${topImgInd}`"
  14. ></component>
  15. </keep-alive>
  16. </div>
  17. <!-- 菜单图片 -->
  18. <div class="menu" @click="myMenucShow = true">
  19. <img src="../assets/img/menu.png" alt="" />
  20. </div>
  21. <!-- 底部菜单选择 -->
  22. <div class="bottom">
  23. <div
  24. class="row"
  25. @click="topImgInd = item.id"
  26. :class="{ active: topImgInd == item.id }"
  27. v-for="item in data"
  28. :key="item.id"
  29. >
  30. <div class="bs"></div>
  31. {{ item.name }}
  32. </div>
  33. </div>
  34. <!-- 下一章节 -->
  35. <div class="next" v-if="topImgInd < data.length" @click="topImgInd++">
  36. 下一章节
  37. </div>
  38. <!-- 卡片 -->
  39. <div class="myMenuc" :class="{ myMenucAc: myMenucShow }">
  40. <Menuc @upInfo="upInfo" />
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. import Menuc from "./menuc/index.vue";
  46. import Son2 from "../components/son2.vue";
  47. import Son3 from "../components/son3.vue";
  48. import Son4 from "../components/son4.vue";
  49. import Son5 from "../components/son5.vue";
  50. import Son6 from "../components/son6.vue";
  51. import Son7 from "../components/son7.vue";
  52. export default {
  53. name: "Home",
  54. components: { Son2, Son3, Son4, Son5, Son6, Son7, Menuc },
  55. data() {
  56. //这里存放数据
  57. return {
  58. myMenucShow: false,
  59. data: [
  60. { id: 1, name: "序言" },
  61. { id: 2, name: "中西贸易" },
  62. { id: 3, name: "鸦片贸易" },
  63. { id: 4, name: "鸦片生产" },
  64. { id: 5, name: "鸦片祸害" },
  65. { id: 6, name: "林则徐禁烟" },
  66. { id: 7, name: "虎门销烟" },
  67. { id: 8, name: "结束语" },
  68. ],
  69. topImgInd: 1,
  70. // 内容动态组件的值
  71. };
  72. },
  73. //监听属性 类似于data概念
  74. computed: {},
  75. //监控data中的数据变化
  76. watch: {
  77. topImgInd() {
  78. window.scrollTo({ top: 0});
  79. },
  80. },
  81. //方法集合
  82. methods: {
  83. upInfo(id) {
  84. this.myMenucShow = false;
  85. this.topImgInd = id;
  86. if (id === this.topImgInd)
  87. window.scrollTo({ top: 0});
  88. },
  89. },
  90. //生命周期 - 创建完成(可以访问当前this实例)
  91. created() {},
  92. //生命周期 - 挂载完成(可以访问DOM元素)
  93. mounted() {},
  94. beforeCreate() {}, //生命周期 - 创建之前
  95. beforeMount() {}, //生命周期 - 挂载之前
  96. beforeUpdate() {}, //生命周期 - 更新之前
  97. updated() {}, //生命周期 - 更新之后
  98. beforeDestroy() {}, //生命周期 - 销毁之前
  99. destroyed() {}, //生命周期 - 销毁完成
  100. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  101. };
  102. </script>
  103. <style lang='less' scoped>
  104. .Home {
  105. padding-bottom: 30px;
  106. width: 100%;
  107. .topImg {
  108. width: 100%;
  109. img {
  110. width: 100%;
  111. vertical-align: middle;
  112. }
  113. }
  114. .main {
  115. background: url("../assets/img/bg.jpg");
  116. background-size: cover;
  117. opacity: 1;
  118. transition: opacity 0.5s;
  119. }
  120. .mainAc {
  121. opacity: 0;
  122. }
  123. .menu {
  124. text-align: right;
  125. padding: 12px 30px 20px 0;
  126. & > img {
  127. width: 61px;
  128. }
  129. }
  130. .bottom {
  131. display: flex;
  132. justify-content: space-around;
  133. background: url("../assets/img/line.png") top left no-repeat;
  134. background-size: 100% 2px;
  135. // border-top: 2px dashed #827d70;
  136. width: 100%;
  137. .row {
  138. position: relative;
  139. letter-spacing: 5px;
  140. padding-top: 15px;
  141. font-size: 14px;
  142. color: #827d70;
  143. writing-mode: vertical-lr;
  144. .bs {
  145. width: 14px;
  146. height: 14px;
  147. position: absolute;
  148. top: -6px;
  149. left: 0;
  150. &::before {
  151. content: "";
  152. border-radius: 50%;
  153. position: absolute;
  154. top: 50%;
  155. left: 50%;
  156. transform: translate(-50%, -50%);
  157. background-color: #827d70;
  158. width: 10px;
  159. height: 10px;
  160. }
  161. }
  162. }
  163. .active {
  164. color: #ebdfbf;
  165. pointer-events: none;
  166. .bs {
  167. left: 1px;
  168. border-radius: 50%;
  169. border: 1px solid #ebdfbf;
  170. &::before {
  171. width: 8px;
  172. height: 8px;
  173. background-color: #ebdfbf;
  174. }
  175. }
  176. }
  177. }
  178. .next {
  179. margin: 28px auto 0;
  180. width: 90px;
  181. padding-left: 30px;
  182. color: #c8b992;
  183. font-size: 14px;
  184. background: url("../assets/img/next.png") left center no-repeat;
  185. background-size: 20px 20px;
  186. }
  187. .myMenuc {
  188. transition: opacity 1s;
  189. z-index: 999;
  190. opacity: 0;
  191. background: url("../assets/img/bodyBac.jpg");
  192. pointer-events: none;
  193. position: fixed;
  194. width: 100vw;
  195. height: 100vh;
  196. top: 0;
  197. left: 0;
  198. }
  199. .myMenucAc {
  200. opacity: 1;
  201. pointer-events: auto;
  202. }
  203. }
  204. .last {
  205. padding-bottom: 80px;
  206. }
  207. </style>