VUE创建使用组件的5种方式

news/2024/7/19 13:05:42 标签: vue, js, javascript, html
htmledit_views">

VUE创建使用组件的5种方式

  • 第一种,以.$mount挂载形式

 

    // 创建构造器
    var Profile = Vue.extend({
        template: '<p>{{firstName}} {{lastName}} aka {{alias}}</p>',
        data: function () {
            return {
                firstName: 'Walter',
                lastName: 'White',
                alias: 'Heisenberg'
            }
        }
    })

// 创建 Profile 实例,并挂载到一个元素上。 

//将组件添加到ID为mount-point的标签上显示

new Profile().$mount('#mount-point')

 

  • 第二种,以id的形式

html" title=js>js代码

Vue.component("div1",{
    template: '#template'
})

html代码

<template id="template">
    <div>我是组件</div>
</template>

 

  • 全局组件,传入Vue.extend对象

Vue.component("p-1",Profile);

 

使用方式,在html内添加标签

<p-1></p-1>

  • 第四种 ,Vue.component  的第二个参数直接传入对象,第二个参数传入后会自动调用 Vue.extend

Vue.component("p-2",{

        template: '<p>{{firstName}} {{lastName}} aka {{alias}}</p>',

        data: function () {

            return {

                firstName: 'Walter',

                lastName: 'White',

                alias: 'Heisenberg'

            }

        }

});

//调用方式,在html内添加如下标签

<p-2></p-2>

 

  • 五种 ,使用components参数局部添加

 

调用方式

<button1></button1>


http://www.niftyadmin.cn/n/740787.html

相关文章

Android安卓使用videoView自定义控件加SeekBar实现视频播放

可以直接复制下面代码直接使用 实现进度条&#xff0c;按下home键从后台回来后处理&#xff0c;自定义控件 1.项目文件结构 2.MainActivity内代码 package io.com.layouttest;import androidx.appcompat.app.AppCompatActivity;import android.annotation.SuppressLint; impo…

textureView的几种回调,多个textureView的判断

textureView(TextureView) findViewById(R.id.textureView);textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {//当TextureView准备好使用Surface的SurfaceTexture时调用。可以使用Overridepublic void onSurfaceTextureAvailable(SurfaceTex…

Android安卓解决textureView播放视频,图片拉伸问题

//设置避免视频播放时拉伸&#xff0c;复制可直接使用private void stretching(float mtextureViewWidth,float mtextureViewHeight){//mtextureViewWidth为textureView宽&#xff0c;mtextureViewHeight为textureView高//mtextureViewWidth宽高&#xff0c;为什么需要用传入的…

Android安卓原生实现微信登陆

在配置文件内加入微信sdkapi com.tencent.mm.opensdk:wechat-sdk-android-without-mta: 在AndroidManifest.xml的manifest节点下添加如下配置&#xff0c;以兼容Android11无法打开微信 <queries><package android:name"com.tencent.mm" /> </querie…

微信小程序事件

touchstart手指触摸动作开始touchmove手指触摸后移动touchcancel手指触摸动作被打断&#xff0c;如来电提醒&#xff0c;弹窗touchend手指触摸动作结束tap手指触摸后马上离开longpress手指触摸后&#xff0c;超过350ms再离开&#xff0c;如果指定了事件回调函数并触发了这个事件…

微信小程序屏幕旋转

屏幕旋转设置&#xff0c;支持 auto / portrait / landscape auto自适应 landscape 固定横屏 portrait 固定竖屏 手机设置&#xff0c;在app.json 的 window 段中设置 {"pageOrientation": "auto" } ipad&#xff0c;pc上面设置支持旋转&#xff0c;…

阿里云服务器使用镜像,跨地域、跨账号复制ECS实例 ,搬家,更换服务器

1.创建镜像 2.复制镜像到目标地区&#xff08;需要在同一地区&#xff0c;更换系统时才能使用创建的镜像&#xff09; 3.共享镜像 4.在新服务器上安装镜像 5.将旧服务器安全组复制到新服务器上 接下来跟着我一起操作 第一步&#xff1a;创建镜像 &#xff08;一&#xf…

微信小程序组件的使用

1.创建一个存放组建的文件夹 2.在根目录app.json输入 "component/zj/zj"&#xff0c;然后可在component快速生成所需文件&#xff0c;生成后好后删除 现在我们看看生成好的文件&#xff0c;见下图 3.添加配置"component": true&#xff0c;可将这组文件声…