亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

vue.js components里data如何做到兩個數據的關聯?

vue.js components里data如何做到兩個數據的關聯?

PIPIONE 2018-08-06 10:10:29
import slider from './slider'export default {     el: '#app',     data () {        return {            someList:[                {                    title: 'slide1',                    img: 'testimg-1.jpg',                },                {                    title: 'slide2',                    img: 'testimg-2.jpg',                },                {                    title: 'slide3',                    img: 'testimg-3.jpg',                }            ],            slideinit: {                pageNum: this.someList.length,                currentPage: 1,                canPre : false,                canNext: true,                start: {},                end: {},                tracking: false,                thresholdTime: 500,                thresholdDistance: 100,            }        }    },    components: {        slider    }}日前,調用slider組件,需要兩個數據,someList和slideinit,slideinit里pageNum等于someList的長度,但this.someList.length報錯,未找到this.someList,請問這個問題應該如何處理?
查看完整描述

1 回答

?
鴻蒙傳說

TA貢獻1865條經驗 獲得超7個贊

slideinit 寫成計算屬性:

export default {

     el: '#app',

     data () {

        return {

            someList:[

                {

                    title: 'slide1',

                    img: 'testimg-1.jpg',

                },

                {

                    title: 'slide2',

                    img: 'testimg-2.jpg',

                },

                {

                    title: 'slide3',

                    img: 'testimg-3.jpg',

                }

            ]

        }

    },

    components: {

        slider

    },

    computed: {

        slideinit () {

            return {

                pageNum: this.someList.length,

                currentPage: 1,

                canPre : false,

                canNext: true,

                start: {},

                end: {},

                tracking: false,

                thresholdTime: 500,

                thresholdDistance: 100,

            }

        }


查看完整回答
反對 回復 2018-09-27
  • 1 回答
  • 0 關注
  • 2568 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號