{"id":901,"date":"2022-06-06T02:40:25","date_gmt":"2022-06-05T18:40:25","guid":{"rendered":"https:\/\/www.jieshop.info\/?p=901"},"modified":"2022-06-06T02:40:25","modified_gmt":"2022-06-05T18:40:25","slug":"swiper%e8%bd%ae%e6%92%ad%e5%9b%be","status":"publish","type":"post","link":"https:\/\/www.jieshop.info\/?p=901","title":{"rendered":"swiper\u8f6e\u64ad\u56fe"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u5b98\u7f51:<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/www.npmjs.com\/package\/vue-awesome-swiper<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">1\u3001swiper\u8f6e\u64ad\u56fe\u7684npm\u4e0b\u8f7d<\/h2>\n\n\n\n<p>\u5b89\u88c5:vue2\u76844.1.1 \u548cswiper5.0x\u7248\u672c<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">npm i vue-awesome-swiper@4.1.1 swiper@5.x -S \/\/\u5b89\u88c5<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2\u3001\u5728\u9700\u8981\u7684\u7ec4\u4ef6\u4e2d\u5f15\u5165<\/h2>\n\n\n\n<p>\u5728export default <strong>\u4e0b\u65b9\u5f15\u5165<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import { Swiper, SwiperSlide } from 'vue-awesome-swiper'<br>import 'swiper\/css\/swiper.css' <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3\u3001\u6ce8\u518c<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">components\uff1a{}\u4e0b\u65b9\u6ce8\u518c<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"> components: {<br> &nbsp;  Swiper,<br> &nbsp;  SwiperSlide,<br> &nbsp;  \/\/ singgerView,<br>  },<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4\u3001\u7ec4\u4ef6\u4e0a\u65b9\u7684template\u91cc\u9762\u5199\u5165<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">banner\u6570\u636e\u662f\u5728data\u91cc\u9762\u8fdb\u884c\u662f\u4e00\u4e2a\u83b7\u53d6<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">data<\/h3>\n\n\n\n<p>data\u91cc\u9762\u7684return\u7684banner\uff1a[]\u6570\u7ec4<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> data() {<br> &nbsp;  return {<br> &nbsp; &nbsp;  banner: [], \/\/\u8f6e\u64ad\u56feswiper<br> &nbsp; &nbsp;  swiperOptions: {<br> &nbsp; &nbsp; &nbsp;  \/\/swiper\u8f6e\u64ad\u56fe\u914d\u7f6e<br> &nbsp; &nbsp; &nbsp;  effect: \"cube\",<br> &nbsp; &nbsp; &nbsp;  grabCursor: true,<br> &nbsp; &nbsp; &nbsp;  cubeEffect: {<br> &nbsp; &nbsp; &nbsp; &nbsp;  shadow: true,<br> &nbsp; &nbsp; &nbsp; &nbsp;  slideShadows: true,<br> &nbsp; &nbsp; &nbsp; &nbsp;  shadowOffset: 5,<br> &nbsp; &nbsp; &nbsp; &nbsp;  shadowScale: 0.78,<br> &nbsp; &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp;  speed: 2500,<br> &nbsp; &nbsp; &nbsp;  autoplay: {<br> &nbsp; &nbsp; &nbsp; &nbsp;  delay: 3000,<br> &nbsp; &nbsp; &nbsp; &nbsp;  stopOnLastSlide: false,<br> &nbsp; &nbsp; &nbsp; &nbsp;  disableOnInteraction: true,<br> &nbsp; &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp;  pagination: {<br> &nbsp; &nbsp; &nbsp; &nbsp;  el: \".swiper-pagination\",<br> &nbsp; &nbsp; &nbsp;  },<br> &nbsp; &nbsp;  },<br> &nbsp;  };<br>  },<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u83b7\u53d6\u8d4b\u503cbanner\u6570\u636e<\/h2>\n\n\n\n<p>methods \u548c\u4e00\u4e2acreated\u751f\u547d\u5468\u671f\u51fd\u6570\u8fdb\u884c\u8c03\u7528\u4e4b\u540e\u5c31\u6709\u6570\u636e<\/p>\n\n\n\n<p>\u7f51\u6613\u4e91\u7684\u63a5\u53e3<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">methods\uff1a<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">  methods: {<br> &nbsp;  \/\/ \u83b7\u53d6\u8f6e\u64ad\u56fe\u7684\u6570\u636e<br> &nbsp;  async getBanners() {<br> &nbsp; &nbsp;  await this.axios.get(\"\/banner\").then((re) =&gt; {<br> &nbsp; &nbsp; &nbsp;  this.banner = re.banners;<br> &nbsp; &nbsp;  });<br> &nbsp;  },<br>  },<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">created\uff08\uff09{}<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"> created() {<br> &nbsp;  \/\/\u8c03\u7528methods\u65b9\u6cd5\u83b7\u53d6\u7684\u65b9\u5f0f<br> &nbsp;  this.getBanners();<br>\u200b<br>  },<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u8c03\u7528<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp;&lt;!-- swiper \u652f\u6301\u79fb\u52a8 \u652f\u6301\u6ed1\u52a8\u6548\u679c... --&gt;<br> &nbsp; &nbsp;&lt;swiper :options=\"swiperOptions\"&gt;<br> &nbsp; &nbsp; &nbsp;&lt;swiper-slide v-for=\"b in banner\" :key=\"b.imageUrl\"&gt;<br> &nbsp; &nbsp; &nbsp; &nbsp;&lt;img :src=\"b.imageUrl\" class=\"banner-item\" \/&gt;<br> &nbsp; &nbsp; &nbsp;&lt;\/swiper-slide&gt;<br> &nbsp; &nbsp; &nbsp;&lt;div class=\"swiper-pagination\" slot=\"pagination\"&gt;&lt;\/div&gt;<br> &nbsp; &nbsp;&lt;\/swiper&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6548\u679c<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"460\" height=\"234\" src=\"https:\/\/www.jieshop.info\/wp-content\/uploads\/2022\/06\/swiper.png\" alt=\"\" class=\"wp-image-902\" srcset=\"https:\/\/www.jieshop.info\/wp-content\/uploads\/2022\/06\/swiper.png 460w, https:\/\/www.jieshop.info\/wp-content\/uploads\/2022\/06\/swiper-300x153.png 300w\" sizes=\"auto, (max-width: 460px) 100vw, 460px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5b98\u7f51: https:\/\/www.npmj&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-901","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"featured_image_urls":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":"","post-thumbnail":"","master-blog-archive":"","master-blog-single":"","master-blog-thumbnail":""},"post_excerpt_stackable":"<p>\u5b98\u7f51: https:\/\/www.npmjs.com\/package\/vue-awesome-swiper 1\u3001swiper\u8f6e\u64ad\u56fe\u7684npm\u4e0b\u8f7d \u5b89\u88c5:vue2\u76844.1.1 \u548cswiper5.0x\u7248\u672c n&hellip;<\/p>\n","category_list":"<a href=\"https:\/\/www.jieshop.info\/?cat=1\" rel=\"category\">\u672a\u5206\u7c7b<\/a>","author_info":{"name":"admin","url":"https:\/\/www.jieshop.info\/?author=1"},"comments_num":"0 comments","_links":{"self":[{"href":"https:\/\/www.jieshop.info\/index.php?rest_route=\/wp\/v2\/posts\/901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jieshop.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jieshop.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jieshop.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jieshop.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=901"}],"version-history":[{"count":1,"href":"https:\/\/www.jieshop.info\/index.php?rest_route=\/wp\/v2\/posts\/901\/revisions"}],"predecessor-version":[{"id":903,"href":"https:\/\/www.jieshop.info\/index.php?rest_route=\/wp\/v2\/posts\/901\/revisions\/903"}],"wp:attachment":[{"href":"https:\/\/www.jieshop.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jieshop.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jieshop.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}