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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器