Should I use Meteor.startup() or $(function() {})

前端 未结 2 1462
悲&欢浪女
悲&欢浪女 2021-01-08 00:35

Do they do the same thing ?

Which one should I use inside client?

if ( Meteor.is_client ) {
    Meteor.startup(function () {
        // my code here
         


        
相关标签:
2条回答
  • 2021-01-08 01:04

    I just ran into an issue that $ was called before template rendering so I hade to use Meteor.startup

    So I'd say that if you need to work with DOM elements you have to use Meteor.startup (I used it for the jQuery File Upload plugin)

    0 讨论(0)
  • 2021-01-08 01:20

    As far as I can tell, Meteor.startup (on the client) is very similar to jQuery's $ function. The main advantage of using it is that it's the same API on client and server, so if you want to write startup code in files that are run on both client and server, Meteor.startup will just work. (Also, I personally find Meteor.startup to be easier to read and more self-documenting than $.)

    0 讨论(0)
提交回复
热议问题