小编A_W*_*Wen的帖子

如何在vue组件中使用setInterval

我在每个my-progress中定义了计时器,用于更新视图的值,但控制台显示常量变化的值,并且视图的值仍未更改,我该如何在计时器中更改值观点

Vue.component('my-progress', {
    template: '\
            <div class="progress progress-bar-vertical" data-toggle="tooltip" data-placement="top">\
                <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" :style="{height: pgvalue}">{{pgvalue}}\
                </div>\
            </div>\
        ',
    data : function(){  

        return {
            pgvalue : '50%',
            intervalid1:'',
        }
    },
    computed:{

        changes : {
            get : function(){
                return this.pgvalue;
            },
            set : function(v){
                this.pgvalue =  v;
            }
        }
    },
    mounted : function(){

        this.todo()     
    },
    beforeDestroy () {

       clearInterval(this.intervalid1)
    },
    methods : {

        todo : function(){          
            this.intervalid1 = setInterval(function(){
                this.changes = ((Math.random() * 100).toFixed(2))+'%';
                console.log (this.changes);
            }, 3000);
        } …
Run Code Online (Sandbox Code Playgroud)

javascript vue-component vuejs2

28
推荐指数
2
解决办法
5万
查看次数

Spring Boot中如何获取文件属性的内容

作为标题,我的自定义属性:

#app settings
my.chassisNum=10
Run Code Online (Sandbox Code Playgroud)

代码:

@PropertySource("classpath:appconf.properties")
@ConfigurationProperties(prefix = "my" )
@Component
public class AppConfig {

    private String chassisNum;

    public String getChassisNum() {
        return this.chassisNum;
    }

    public void setChassisNum(String chassisNum) {
        this.chassisNum = chassisNum;
    }
}
Run Code Online (Sandbox Code Playgroud)

当 Spring Boot 启动完成时,我得到的“chassisNum”值为 10。当我在 spring-boot 未启动完成时在其他地方得到它时,它得到“null”

@Component
public class CreateBaseFolder {

    private final Logger logger = LogManager.getLogger(CreateBaseFolder.class);
    private File f; 
    @Autowired
    AppConfig appconf;

    public CreateBaseFolder() {

        System.out.println(appconf.getChassisNum());


    } 
Run Code Online (Sandbox Code Playgroud)

我尝试了很多方法来获取它的价值,但都是错误的。例如:实现 InitializingBean、@DependsOn ....

spring-boot

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×1

spring-boot ×1

vue-component ×1

vuejs2 ×1