[英]How to create variable that uses props, and display value in Nuxt.js
I am using Nuxt.js with normal javascript.我正在使用 Nuxt.js 和普通的 javascript。 I have two props that are numbers.我有两个数字道具。 I want to take these props and calculate a percentage that i will then display in my template area.我想获取这些道具并计算一个百分比,然后我将在我的模板区域中显示该百分比。
Is this possible, and how can i achieve this?这是可能的,我怎样才能做到这一点? I have tried among others the following, but it's not working and I am not really known with JS.我尝试过以下其他方法,但它不起作用,而且我对 JS 并不了解。
<template>
<div class="progress">
<div role="progressbar" :aria-valuenow="goal_progress" aria-valuemin="0" aria-valuemax="100" class="progress-bar" :style="'width: ' + goal_progrress + '%';">{{goal_progress}}%</div>
</div>
</template>
<script>
var goal_progress = (prop1 / prop2) * 100;
export default {
props: {
prop1: Number,
prop2: Number,
}
}
</script>
In the index.vue i pass the following values.在 index.vue 中,我传递了以下值。
<Example
prop1=100
prop2=1000 />
Use a computed property as follows :使用计算属性如下:
export default {
props: {
prop1: Number,
prop2: Number,
}
},
computed:{
goal_progress (){
return (this.prop1 / this.prop2) * 100;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.