vue 第一天(基本的结构)

vue 第一天(基本的结构)

el就像我们的选择器一样 里面是 # 就是id选择器 里面是 . 就是class选择器 直接写标签就是标签选择器 也可以id+class 或 多个id 等
data相当于我们 el 表达式或者 thymeleaf 一样 上面格式用 { {key}} 下面在data里面定义key和value
data中可以写数组还有对象。

methods里面定义方法就像js里的函数一样

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script rel="javascript" src="../lib/vue.js"></script>
</head>
<body>
<div id="vue_one">
    <h1>site : {
    
    {
    
    site}}</h1>
    <h1>{
    
    {
    
    url}}</h1>
    <h1>{
    
    {
    
    details()}}</h1>
    <h1>{
    
    {
    
    no()}}</h1>
    <h1>{
    
    {
    
    shuzu}}</h1>
    <h1>{
    
    {
    
    obj}}</h1>
</div>
<script type="text/javascript">
    const obj = {
    
    
        duixiang : "我是对象那个",
        duixiang2 : "我也是"
    }
    const vm = new Vue({
    
    
        el: '#vue_one',
        data: {
    
    
            site: "我的第一个vue程序",
            url: "网址吗还没定",
            shuzu : ["篮球","足球","动漫"],
            obj
        },
        methods: {
    
    
            details: function() {
    
    
                return this.site + "- 要坚持下去";
            },
            no :function () {
    
    
                return this.details() +"- 没有什么不可以";
            }
        }
    })
</script>
</body>
</html>






花开一千年,花落一千年,花叶永不见

猜你喜欢

转载自blog.csdn.net/weixin_43731532/article/details/114131203
今日推荐