欢迎莅临 SUN WU GANG 的园子!!!

世上无难事,只畏有心人。有心之人,即立志之坚午也,志坚则不畏事之不成。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

示例代码如下所示:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue模版语法学习</title>
    <script type="text/javascript" src="../Js/vue.js"></script>
</head>

<body>
    <div id="root">
        <h1>插值语法</h1>
        <h1>插值语法,用于标签体内</h1>
        <h1>hello {{name}}</h1>
        <h1>Vue {{nickname}}</h1>
        <hr />
        <h1>Vue指令语法,用于标签属性</h1>
        <h1>注:v-bind:可简写为:</h1>
        <a v-bind:href="url">百度一下</a>
        <a :href="url">百度一下</a>
        <hr />
        <a v-bind:href="url.toUpperCase()">百度一下</a>
        <!-- <a :href="url.toLowCase()">百度一下</a> -->
        <h1>获取当前时间戳: {{Date.now()}}</h1>
        <hr />
        <h1> {{mydata.oneAtt}}</h1>
        <h1> {{mydata.towAtt}}</h1>
        <hr />
        <h1>hello {{name.toUpperCase()}}</h1>
        <h1>转大写:{{textlowupper.toUpperCase()}}</h1>
        <h1>转小写:{{textlowupper.toLowerCase()}}</h1>
    </div>
</body>

</html>

<script type="text/javascript">
    Vue.config.productionTip = false

    const one = new Vue({
        // 方式一:通过id选择器获取对象,也可理解为获取容器
        el: '#root',
        data: {
            name: 'vue',
            nickname: 'vue.js',
            url: 'https://www.baidu.com/',
            textlowupper: 'AbcdEfg',
            // data 对象中可嵌套多层对象哦
            mydata:
            {
                oneAtt: '我是一个嵌套对象的属性哦',
                towAtt: '我是嵌套对象的第二个属性哦'
            }
        },
    })


</script>

运行效果:

 总结:

 

posted on 2024-02-22 10:42  sunwugang  阅读(18)  评论(0)    收藏  举报