实现Vue加载动画,同时从URL加载图片
P粉021854777
P粉021854777 2023-08-03 18:04:16
0
1
455
<p>我想在图片加载时显示加载动画,但我不知道如何实现。<br /><br />虽然没有加载器,但我进行了调试,控制台上显示了"true"和"false",但仍然没有加载动画出现。</p><p><br /></p> <pre class="brush:php;toolbar:false;">&lt;template&gt; &lt;div class="KingOfMountain"&gt; &lt;Spinner v-if="isLoading"/&gt; //// ERROR &lt;div v-else class="container"&gt; &lt;div v-if="!isEndGameKing" class="choices"&gt; &lt;p id="score"&gt;{{ currentCountKing }}/{{ ALL_FILMS.length - 1 }} &lt;p/&gt; &lt;div class="photos"&gt; &lt;div class="first__film"&gt; &lt;img :src="firstFilm.Poster" :alt="firstFilm.title" @click="chooseLeftFilm"&gt; &lt;p id="title--film"&gt;{{ firstFilm.title }}&lt;/p&gt; &lt;/div&gt; &lt;div class="second__film"&gt; &lt;img :src="secondFilm.Poster" :alt="secondFilm.title" @click="chooseRightFilm"&gt; &lt;p id="title--film"&gt;{{ secondFilm.title }}&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div v-else class="winner"&gt; &lt;p id="winner--title"&gt;Победитель&lt;/p&gt; &lt;img :src="firstFilm.Poster" :alt="firstFilm.title"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/template&gt; &lt;script&gt; import game from "@/mixins/game"; import Spinner from "@/components/Spinner/Spinner"; //all good in css . it works export default { name: "KingOfMountain", data() { return{ isLoading:false } }, components: {Spinner}, methods: { chooseLeftFilm() { this.isLoading=true this.redirectToResultKing() // it is method in mixins (all Good, it works) this.isLoading=false }, chooseRightFilm() { this.isLoading=true this.firstFilm = this.secondFilm; this.redirectToResultKing() // it is method in mixins (all Good, it works) this.isLoading=false } }, } &lt;/script&gt;</pre> <p>如果我像这样使用,它会显示加载动画:</p> <pre class="brush:php;toolbar:false;">chooseLeftFilm() { this.isLoading=true this.redirectToResultKing() // it is method in mixins (all Good, it works) },</pre> <p>// it will spinner forever</p> <p>帮我,如何更好地制作加载动画?</p> <p>我的混入(mixins):</p> <pre class="brush:php;toolbar:false;">export default { methods: { updateFilm() { // Here i random take 2 images from Vuex and then them delete and etc... this.currentCountKing++; this.allFilmsKingCopy = this.allFilmsKingCopy.filter(val =&gt; val !== this.secondFilm) this.secondFilm = this.allFilmsKingCopy[Math.floor(Math.random() * this.allFilmsKingCopy.length)] }, redirectToResultKing() { if (this.currentCountKing === this.ALL_FILMS.length - 1) { this.isEndGameKing = true } else { this.updateFilm() } } }, computed: { ...mapGetters(['ALL_FILMS']), },</pre> <p>我的 Vuex:</p> <pre class="brush:php;toolbar:false;">export default { state: { films: [], }, actions: { async getFilms({commit}) { const data = await fetch(URL); const dataResponse = await data.json(); const films=dataResponse.data commit("setData", films) }, }, mutations: { setData(state, films) { state.films = films }, }, getters: { ALL_FILMS(state) { return state.films }, } }</pre> <p><br /></p>
P粉021854777
P粉021854777

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!