vue.js - vue访问不了变量

查看:340
本文介绍了vue.js - vue访问不了变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

图片不能显示没有获得url的值
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript" src="js/vue.js" ></script>
    <script>
        window.onload=function(){
            new Vue({
                el:'#box',//选择器
                data:{
                    url:'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png'
                },
                methods:{
                }
            });
        }
    </script>
</head>
<body>
    <div id="box">
        <img src="{{url}}" />
    </div>
</body>

</html>

解决方案

你的代码有1处错误,src的赋值错误,src的赋值既然是动态的,就要用v-bind:src,简写:src。

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript" src="js/vue.js" ></script>
    <script>
        window.onload=function(){
            new Vue({
                el:'#box',//选择器
                data:{
                        url:'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png'
                },
                methods:{
                }
            });
        }
    </script>
</head>
<body>
    <div id="box">
        <img :src="url" />
    </div>
</body>
</html>

这篇关于vue.js - vue访问不了变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆