nayuxuohz

vue.js 如何获取自定义 component 上的属性值?

  •  1
     
  •   nayuxuohz · Apr 22, 2016 · 11172 views
    This topic created in 3723 days ago, the information mentioned may be changed or developed.

    <sbx url="/"></sbx>

    如上面 sbx 的 url 属性,只是单纯字符,页面上由后台写入

    sbx是独立的vue文件,所以后台变量不能写在里面

    var Sbx = Vue.extend({ ... });

    不会用markdown... XD

    那如何在实例中获取到呢?

    5 replies    2016-04-25 10:54:37 +08:00
    SourceMan
        1
    SourceMan  
       Apr 22, 2016 via iPhone
    props
    NemoAlex
        2
    NemoAlex  
       Apr 22, 2016 via iPhone
    问题描述得不清楚。既然是 vue 文件,那么应该是用 webpack 之类的打包吧?这样的应用怎么还要服务器端生成 html ?
    如果只是变量传递,使用 binding 的方式 :url ,然后在组件里 props 定义一下,就可以用了。
    airyland
        3
    airyland  
       Apr 22, 2016
    看文档的组件部分
    chairuosen
        4
    chairuosen  
       Apr 22, 2016
    props 定义,作为实例属性就能获取
    nayuxuohz
        5
    nayuxuohz  
    OP
       Apr 25, 2016
    @NemoAlex 用的 browserify 打包,不是服务端生成 html , 是有个参数要通过后台写到页面上,如 html 里有<app url="/"></app>, vue 文件则是打包,现在解决了,在 attached 事件中 this.url 就是,这里有些奇耙
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1496 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 16:47 · PVG 00:47 · LAX 09:47 · JFK 12:47
    ♥ Do have faith in what you're doing.