javascript - Vue 数据绑定问题
ringa_lee
ringa_lee 2017-04-11 10:31:27
[JavaScript讨论组]

我是VUE初学者, 想请教大家一个数据绑定的问题.
我的业务上有一个这样的场景.
我需要上传N种尺寸类型的图片,每种尺寸的规则我都预先设置好了,我想在我选择尺寸的时候,切换我的配置,然后在上传的时候再做校验是否符合规则.
现在遇到的问题是,
我在选择图片类型的时候,数据的值会发生变化,但是在提交代码的时候值没变,我试过用setTimeout 来解决也不管用,请大家帮我看看,

主干代码如图:
HTML

{loop $imgTypeCfg $item} {/loop}

对应的JS

var Form = new Vue({                                                                                                                                                       
    el: '#add_gallery_form',
    data: { 
        imgTypeCfg: {json_encode($imgTypeCfg)},
        imgCfg:{ size:1000*1024, width:1226, height:460, },
        bigImgCfg: { size: 1000 * 1024, width: 1226, height: 460 },
        smallImgCfg: { size: 1000 * 1024, width: 295, height:175 },
    },      
    methods: {
        changeRadio:function(){
            $data = this.$data;
            var img_type =$("input[name='img_type']:checked").val();
            if (img_type==1){// 大图
                $data.imgCfg.width = $data.bigImgCfg.width;
                $data.imgCfg.height= $data.bigImgCfg.height;
            }else{ // 小图2
                $data.imgCfg.width = $data.smallImgCfg.width;
                $data.imgCfg.height= $data.smallImgCfg.height;
            }
        },  
        refreshTable: function () {
            var $data = this.$data;
            // filestyle
            $("input[name='img_file']").filestyle().each(function () {
                var $this = $(this);                                                                                                               
                $this.ajaxfileupload({
                    action: '/index.php?m=xxxxxx-image&do=ajaxUploadImage',
                    params: function () {
                        return {
                            max_size: $this.data("size"),
                            img_width: $this.data("width"),
                            img_height: $this.data("height")
                        }
                    }(),
                    onStart: function () {
                        $this.filestyle('disabled', true);
                    },
                    onComplete: function (response) {
                        $this.filestyle('disabled', false);
                        if (response.status === false) {
                            showAlertMsg("warning", response.message);
                            return;
                        }
                        if (response.code == 200) {
                            $this.siblings(".input-hidden").val(response.ext.path).change();
                        } else {
                            showAlertMsg('error', response.message);
                        }
                    }
                   });
            });
ringa_lee
ringa_lee

ringa_lee

全部回复(1)
怪我咯
v-bind="{'data-width':imgCfg.width,'data-size':imgCfg.size,'data-height':imgCfg.height}"

v-bind 不是这么用的

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号