L-YASHU 2017-07-27 11:30 采纳率: 41.7%
浏览 1729
已采纳

Vue.js 关于Vue.js中样式引入问题

 <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Vue.js组件</title>
    </head>
    <body>
        <div id="app">
            <counter heading="完美极了" bgcolor="green"></counter>
            <counter heading="糟糕透了" bgcolor="red"></counter>
        </div>

            <template id="mycounter">
                <div class="">
                    <h1>{{ heading }}</h1>
                    <button type="button" name="button" @click="plus" style="background:{{ bgcolor }}">赞赞赞{{ count }}</button>
                </div>
            </template>
        <script src="vue.js" type="text/javascript"></script>
        <script type="text/javascript">
            Vue.component("counter",{
                template:"#mycounter",
                data:function(){
                    return { count : 0};
                },
                props:["heading","bgcolor"],
                methods : {
                    plus : function(){
                        this.count += 1;
                    }
                }
            });
            new Vue({
                el : "#app"
            });
        </script>
    </body>
</html>

上面的代码中
赞赞赞{{ count }}
这一行报错,报错信息为:
Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of

, use
.
改为:
赞赞赞{{ count }}
后仍然报错!
请问大家,这里应该怎么正确引入父组件传过来的bgcolor作为button的背景色?
  • 写回答

1条回答

  • JPF1024 2017-07-27 14:38
    关注

    参考:

    https://cn.vuejs.org/v2/guide/class-and-style.html

    官方例子:
    
    <div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
    
    data: {
      activeColor: 'red',
      fontSize: 30
    }
    
    你的可以改成:
    
    <button type="button" name="button" @click="plus" v-bind:style="{background: bgcolor }">赞赞赞{{ count }}</button>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条