zoukankan      html  css  js  c++  java
  • vue 组件开发

     作者QQ:1095737364    QQ群:123300273     欢迎加入!

    1.新建路由:router-->index.js,修改成下面的代码

    import Vue from 'vue'
    import Router from 'vue-router'
    import index from '@/components/index/index'
    Vue.use(Router)
    export default new Router({
        mode:'history',
        routes: [
            {
            path: '/',
            name: 'index',
            component: index
        },
        ]
    })

    2.在components文件夹下新建index文件夹,在index 文件夹下新建:index.vue

    <template>
        <div class="">
        </div>
    </template>
    <script>
    export default {
        data () {
            return {}
        },
        props: {},
        computed: {},
        components: {},
        methods: {},
        watch: {},
    }
    </script>
    <style scoped>
    </style>

    3.绑定数据

      1.单个数据绑定

    <template>
    <div class="content">
        <span v-text="pageDate.id"></span>
        <span v-text="pageDate.url"></span>
        <span v-text="pageDate.href"></span>
    </div>
    </template>
     
    <script>
    var pageDate =
        {
        id: 10000, //该广告的ID
        url: 'http://163.com', //广告图片路径
        href: 'http://baidu.com'//点击跳转连接
        }
    export default {
        data () {
            return {
                pageDate
            }
        },
        props: {},
        computed: {},
        components: {},
        methods: {},
        watch: {},
    }
    </script>
    <style scoped>
    </style>            
     
          注意: href 和src 有其特定的方式来绑定数据:
          <a :href="pageDate.href"></a>
          <img :src="pageDate.url" >

      2.多条数据绑定:

    <template>
    <!-- v-for 表情表示循环输出数据:必须要有父类dom,否则会出错的-->
    <div>
        <div v-for="item in pageDate">
        <span v-text="item.id"></span>
        <span v-text="item.url"></span>
        <span v-text="item.href"></span>
    </div>
    </div>
    </template>
    <script>
    var pageDate =[
        {
        id: 10000, //该广告的ID
        url: 'http://163.com', //广告图片路径
        href: 'http://baidu.com'//点击跳转连接
        },
        {
        id: 10002, //该广告的ID
        url: 'http://163.com', //广告图片路径
        href: 'http://baidu.com'//点击跳转连接
        }]
    export default {
        data () {
            return {
                pageDate
            }
        },
        props: {},
        computed: {},
        components: {},
        methods: {},
        watch: {},
    }
    </script>
    <style scoped>
    </style>

      3.增删改

    <template>
        <!-- v-for 表情表示循环输出数据:必须要有父类dom,否则会出错的-->
     <div>
        <div v-for="item in pageDate">
            <span v-text="item.id"></span>
            <span v-text="item.url"></span>
            <span v-text="item.href"></span>
        <button @click="detele()"> 删除数据</button>
        </div>
        <button @click="add"> 添加数据</button>
        <button @click="update"> 修改数据</button>
    </div>
    </template>
    <script>
    var pageDate = [
        {
            id: 10000, //该广告的ID
            url: 'http://163.com', //广告图片路径
            href: 'http://baidu.com'//点击跳转连接
        },
        {
            id: 10002, //该广告的ID
            url: 'http://163.com', //广告图片路径
            href: 'http://baidu.com'//点击跳转连接
        }
        ]
    export default {
        data () {
            return {
                pageDate
            }
        },
        props: {},
        computed: {},
        components: {},
        methods: {
        add: function () {
        this.pageDate.push({
            id: 10003, //该广告的ID
            url: 'http://163.com', //广告图片路径
            href: 'http://baidu.com'//点击跳转连接
        })
    },
    update: function () {
        this.pageDate[1].id = 10000000000000000000
    },
    detele: function (index) {
        this.pageDate.splice(index, 1)
    }
    },
    watch: {},
    }
    </script>
    <style scoped>
    </style>    
     
     
     
     
     
     
  • 相关阅读:
    免费素材下载:淡蓝色的PSD格式UI套件
    分享一个CSS3的网格系统架构 ResponsiveAeon
    最新收集的超棒Mobile/Web UI和用户体验设计
    一个帮助你针对不同标签自动填入内容的轻量级javascript类库 fixiejs
    发现任何VB函数、插件、甚至按键精灵对“文件下载”窗口后台失效
    android 界面 滑入 效果
    分布式HeadLoop
    VB ListView
    android 下载保存图片
    网址
  • 原文地址:https://www.cnblogs.com/yysbolg/p/7348867.html
Copyright © 2011-2022 走看看